How to use addSysproperty method of org.testng.TestNGAntTask class

Best Testng code snippet using org.testng.TestNGAntTask.addSysproperty

Source:TestNGAntTask.java Github

copy

Full Screen

...253 }254 public Commandline.Argument createJvmarg() {255 return getJavaCommand().createVmArgument();256 }257 public void addSysproperty(Environment.Variable sysp) {258 getJavaCommand().addSysproperty(sysp);259 }260 /** Adds an environment variable; used when forking. */261 public void addEnv(Environment.Variable var) {262 m_environment.addVariable(var);263 }264 /**265 * Adds path to classpath used for tests.266 *267 * @return reference to the classpath in the embedded java command line268 */269 public Path createClasspath() {270 return getJavaCommand().createClasspath(getProject()).createPath();271 }272 /**273 * Adds a path to the bootclasspath.274 *275 * @return reference to the bootclasspath in the embedded java command line276 */277 public Path createBootclasspath() {278 return getJavaCommand().createBootclasspath(getProject()).createPath();279 }280 /**281 * Set the classpath to be used when running the Java class282 *283 * @param s an Ant Path object containing the classpath.284 */285 public void setClasspath(Path s) {286 createClasspath().append(s);287 }288 /**289 * Classpath to use, by reference.290 *291 * @param r a reference to an existing classpath292 */293 public void setClasspathRef(Reference r) {294 createClasspath().setRefid(r);295 }296 public void addXmlfileset(FileSet fs) {297 m_xmlFilesets.add(fs);298 }299 public void setXmlfilesetRef(Reference ref) {300 m_xmlFilesets.add(createResourceCollection(ref));301 }302 public void addClassfileset(FileSet fs) {303 m_classFilesets.add(appendClassSelector(fs));304 }305 public void setClassfilesetRef(Reference ref) {306 m_classFilesets.add(createResourceCollection(ref));307 }308 public void setTestNames(String testNames) {309 m_testNames = testNames;310 }311 /**312 * Sets the suite runner class to invoke313 *314 * @param s the name of the suite runner class315 */316 public void setSuiteRunnerClass(String s) {317 m_mainClass = s;318 }319 /**320 * Sets the suite name321 *322 * @param s the name of the suite323 */324 public void setSuiteName(String s) {325 m_suiteName = s;326 }327 /**328 * Sets the test name329 *330 * @param s the name of the test331 */332 public void setTestName(String s) {333 m_testName = s;334 }335 // TestNG settings336 public void setJUnit(boolean value) {337 mode = value ? Mode.junit : Mode.testng;338 }339 // TestNG settings340 public void setMode(Mode mode) {341 this.mode = mode;342 }343 /**344 * Sets the test output directory345 *346 * @param dir the name of directory347 */348 public void setOutputDir(File dir) {349 m_outputDir = dir;350 }351 /**352 * Sets the test jar353 *354 * @param s the name of test jar355 */356 public void setTestJar(File s) {357 m_testjar = s;358 }359 public void setGroups(String groups) {360 m_includedGroups = groups;361 }362 public void setExcludedGroups(String groups) {363 m_excludedGroups = groups;364 }365 private Integer m_verbose = null;366 private Integer m_suiteThreadPoolSize;367 private String m_xmlPathInJar;368 public void setVerbose(Integer verbose) {369 m_verbose = verbose;370 }371 public void setReporter(String listener) {372 m_listeners.add(listener);373 }374 public void setObjectFactory(String className) {375 m_objectFactory = className;376 }377 public void setTestRunnerFactory(String testRunnerFactory) {378 m_testRunnerFactory = testRunnerFactory;379 }380 public void setSuiteThreadPoolSize(Integer n) {381 m_suiteThreadPoolSize = n;382 }383 public void setListeners(String listeners) {384 StringTokenizer st = new StringTokenizer(listeners, " ,");385 while (st.hasMoreTokens()) {386 m_listeners.add(st.nextToken());387 }388 }389 public void setMethodSelectors(String methodSelectors) {390 StringTokenizer st = new StringTokenizer(methodSelectors, " ,");391 while (st.hasMoreTokens()) {392 m_methodselectors.add(st.nextToken());393 }394 }395 public void setConfigFailurePolicy(String failurePolicy) {396 m_configFailurePolicy = failurePolicy;397 }398 public void setRandomizeSuites(Boolean randomizeSuites) {399 m_randomizeSuites = randomizeSuites;400 }401 public void setMethods(String methods) {402 m_methods = methods;403 }404 /**405 * Launches TestNG in a new JVM.406 *407 * <p>{@inheritDoc}408 */409 @Override410 public void execute() throws BuildException {411 validateOptions();412 CommandlineJava cmd = getJavaCommand();413 cmd.setClassname(m_mainClass);414 if (m_assertEnabled) {415 cmd.createVmArgument().setValue("-ea");416 }417 if (m_delegateCommandSystemProperties) {418 delegateCommandSystemProperties();419 }420 List<String> argv = createArguments();421 String fileName = "";422 FileWriter fw = null;423 BufferedWriter bw = null;424 try {425 File f = File.createTempFile("testng", "");426 fileName = f.getAbsolutePath();427 // If the user asked to see the command, preserve the file428 if (!m_dump) {429 f.deleteOnExit();430 }431 fw = new FileWriter(f);432 bw = new BufferedWriter(fw);433 for (String arg : argv) {434 bw.write(arg);435 bw.newLine();436 }437 bw.flush();438 } catch (IOException e) {439 LOGGER.error(e.getMessage(), e);440 } finally {441 try {442 if (bw != null) {443 bw.close();444 }445 if (fw != null) {446 fw.close();447 }448 } catch (IOException e) {449 LOGGER.error(e.getMessage(), e);450 }451 }452 printDebugInfo(fileName);453 createClasspath().setLocation(findJar());454 cmd.createArgument().setValue("@" + fileName);455 ExecuteWatchdog watchdog = createWatchdog();456 boolean wasKilled = false;457 int exitValue = executeAsForked(cmd, watchdog);458 if (null != watchdog) {459 wasKilled = watchdog.killedProcess();460 }461 actOnResult(exitValue, wasKilled);462 }463 protected List<String> createArguments() {464 List<String> argv = Lists.newArrayList();465 addBooleanIfTrue(argv, CommandLineArgs.JUNIT, mode == Mode.junit);466 addBooleanIfTrue(argv, CommandLineArgs.MIXED, mode == Mode.mixed);467 addBooleanIfTrue(468 argv, CommandLineArgs.SKIP_FAILED_INVOCATION_COUNTS, m_skipFailedInvocationCounts);469 addIntegerIfNotNull(argv, CommandLineArgs.LOG, m_verbose);470 addDefaultListeners(argv);471 addOutputDir(argv);472 addFileIfFile(argv, CommandLineArgs.TEST_JAR, m_testjar);473 addStringIfNotBlank(argv, CommandLineArgs.GROUPS, m_includedGroups);474 addStringIfNotBlank(argv, CommandLineArgs.EXCLUDED_GROUPS, m_excludedGroups);475 addFilesOfRCollection(argv, CommandLineArgs.TEST_CLASS, m_classFilesets);476 addListOfStringIfNotEmpty(argv, CommandLineArgs.LISTENER, m_listeners);477 addListOfStringIfNotEmpty(argv, CommandLineArgs.METHOD_SELECTORS, m_methodselectors);478 addStringIfNotNull(argv, CommandLineArgs.OBJECT_FACTORY, m_objectFactory);479 addStringIfNotNull(argv, CommandLineArgs.TEST_RUNNER_FACTORY, m_testRunnerFactory);480 addStringIfNotNull(argv, CommandLineArgs.PARALLEL, m_parallelMode);481 addStringIfNotNull(argv, CommandLineArgs.CONFIG_FAILURE_POLICY, m_configFailurePolicy);482 addBooleanIfTrue(argv, CommandLineArgs.RANDOMIZE_SUITES, m_randomizeSuites);483 addStringIfNotNull(argv, CommandLineArgs.THREAD_COUNT, m_threadCount);484 addStringIfNotNull(argv, CommandLineArgs.DATA_PROVIDER_THREAD_COUNT, m_dataproviderthreadCount);485 addStringIfNotBlank(argv, CommandLineArgs.SUITE_NAME, m_suiteName);486 addStringIfNotBlank(argv, CommandLineArgs.TEST_NAME, m_testName);487 addStringIfNotBlank(argv, CommandLineArgs.TEST_NAMES, m_testNames);488 addStringIfNotBlank(argv, CommandLineArgs.METHODS, m_methods);489 addReporterConfigs(argv);490 addIntegerIfNotNull(argv, CommandLineArgs.SUITE_THREAD_POOL_SIZE, m_suiteThreadPoolSize);491 addStringIfNotNull(argv, CommandLineArgs.XML_PATH_IN_JAR, m_xmlPathInJar);492 addXmlFiles(argv);493 return argv;494 }495 private void addDefaultListeners(List<String> argv) {496 if (m_useDefaultListeners != null) {497 String useDefaultListeners = "false";498 if ("yes".equalsIgnoreCase(m_useDefaultListeners)499 || "true".equalsIgnoreCase(m_useDefaultListeners)) {500 useDefaultListeners = "true";501 }502 argv.add(CommandLineArgs.USE_DEFAULT_LISTENERS);503 argv.add(useDefaultListeners);504 }505 }506 private void addOutputDir(List<String> argv) {507 if (null != m_outputDir) {508 if (!m_outputDir.exists()) {509 m_outputDir.mkdirs();510 }511 if (m_outputDir.isDirectory()) {512 argv.add(CommandLineArgs.OUTPUT_DIRECTORY);513 argv.add(m_outputDir.getAbsolutePath());514 } else {515 throw new BuildException("Output directory is not a directory: " + m_outputDir);516 }517 }518 }519 private void addReporterConfigs(List<String> argv) {520 for (ReporterConfig reporterConfig : reporterConfigs) {521 argv.add(CommandLineArgs.REPORTER);522 argv.add(reporterConfig.serialize());523 }524 }525 private void addFilesOfRCollection(526 List<String> argv, String name, List<ResourceCollection> resources) {527 addArgumentsIfNotEmpty(argv, name, getFiles(resources), ",");528 }529 private void addListOfStringIfNotEmpty(List<String> argv, String name, List<String> arguments) {530 addArgumentsIfNotEmpty(argv, name, arguments, ";");531 }532 private void addArgumentsIfNotEmpty(533 List<String> argv, String name, List<String> arguments, String separator) {534 if (arguments != null && !arguments.isEmpty()) {535 argv.add(name);536 String value = Utils.join(arguments, separator);537 argv.add(value);538 }539 }540 private void addFileIfFile(List<String> argv, String name, File file) {541 if ((null != file) && file.isFile()) {542 argv.add(name);543 argv.add(file.getAbsolutePath());544 }545 }546 private void addBooleanIfTrue(List<String> argv, String name, Boolean value) {547 if (TRUE.equals(value)) {548 argv.add(name);549 }550 }551 private void addIntegerIfNotNull(List<String> argv, String name, Integer value) {552 if (value != null) {553 argv.add(name);554 argv.add(value.toString());555 }556 }557 private void addStringIfNotNull(List<String> argv, String name, String value) {558 if (value != null) {559 argv.add(name);560 argv.add(value);561 }562 }563 private void addStringIfNotBlank(List<String> argv, String name, String value) {564 if (isStringNotBlank(value)) {565 argv.add(name);566 argv.add(value);567 }568 }569 private void addXmlFiles(List<String> argv) {570 for (String file : getSuiteFileNames()) {571 argv.add(file);572 }573 }574 /** @return the list of the XML file names. This method can be overridden by subclasses. */575 protected List<String> getSuiteFileNames() {576 List<String> result = Lists.newArrayList();577 for (String file : getFiles(m_xmlFilesets)) {578 result.add(file);579 }580 return result;581 }582 private void delegateCommandSystemProperties() {583 // Iterate over command-line args and pass them through as sysproperty584 // exclude any built-in properties that start with "ant."585 for (Object propKey : getProject().getUserProperties().keySet()) {586 String propName = (String) propKey;587 String propVal = getProject().getUserProperty(propName);588 if (propName.startsWith("ant.")) {589 log("Excluding ant property: " + propName + ": " + propVal, Project.MSG_DEBUG);590 } else {591 log("Including user property: " + propName + ": " + propVal, Project.MSG_DEBUG);592 Environment.Variable var = new Environment.Variable();593 var.setKey(propName);594 var.setValue(propVal);595 addSysproperty(var);596 }597 }598 }599 private void printDebugInfo(String fileName) {600 if (m_dumpSys) {601 debug("* SYSTEM PROPERTIES *");602 Properties props = System.getProperties();603 Enumeration en = props.propertyNames();604 while (en.hasMoreElements()) {605 String key = (String) en.nextElement();606 debug(key + ": " + props.getProperty(key));607 }608 debug("");609 }610 if (m_dumpEnv) {611 String[] vars = m_environment.getVariables();612 if (null != vars && vars.length > 0) {613 debug("* ENVIRONMENT *");614 for (String v : vars) {615 debug(v);616 }617 debug("");618 }619 }620 if (m_dump) {621 dumpCommand(fileName);622 }623 }624 private void debug(String message) {625 log("[TestNGAntTask] " + message, Project.MSG_DEBUG);626 }627 protected void actOnResult(int exitValue, boolean wasKilled) {628 if (exitValue == -1) {629 executeHaltTarget(exitValue);630 throw new BuildException("an error occurred when running TestNG tests");631 }632 if ((exitValue & ExitCode.HAS_NO_TEST) == ExitCode.HAS_NO_TEST) {633 if (m_haltOnFailure) {634 executeHaltTarget(exitValue);635 throw new BuildException("No tests were run");636 } else {637 if (null != m_failurePropertyName) {638 getProject().setNewProperty(m_failurePropertyName, "true");639 }640 log("TestNG haven't found any tests to be run", Project.MSG_DEBUG);641 }642 }643 boolean failed = (ExitCode.hasFailure(exitValue)) || wasKilled;644 if (failed) {645 final String msg = wasKilled ? "The tests timed out and were killed." : "The tests failed.";646 if (m_haltOnFailure) {647 executeHaltTarget(exitValue);648 throw new BuildException(msg);649 } else {650 if (null != m_failurePropertyName) {651 getProject().setNewProperty(m_failurePropertyName, "true");652 }653 log(msg, Project.MSG_INFO);654 }655 }656 if (ExitCode.hasSkipped(exitValue)) {657 if (m_haltOnSkipped) {658 executeHaltTarget(exitValue);659 throw new BuildException("There are TestNG SKIPPED tests");660 } else {661 if (null != m_skippedPropertyName) {662 getProject().setNewProperty(m_skippedPropertyName, "true");663 }664 log("There are TestNG SKIPPED tests", Project.MSG_DEBUG);665 }666 }667 if (ExitCode.hasFailureWithinSuccessPercentage(exitValue)) {668 if (m_haltOnFSP) {669 executeHaltTarget(exitValue);670 throw new BuildException("There are TestNG FAILED WITHIN SUCCESS PERCENTAGE tests");671 } else {672 if (null != m_fspPropertyName) {673 getProject().setNewProperty(m_fspPropertyName, "true");674 }675 log("There are TestNG FAILED WITHIN SUCCESS PERCENTAGE tests", Project.MSG_DEBUG);676 }677 }678 }679 /** Executes the target, if any, that user designates executing before failing the test */680 private void executeHaltTarget(int exitValue) {681 if (m_onHaltTarget != null) {682 if (m_outputDir != null) {683 getProject().setProperty("testng.outputdir", m_outputDir.getAbsolutePath());684 }685 getProject().setProperty("testng.returncode", String.valueOf(exitValue));686 Target t = getProject().getTargets().get(m_onHaltTarget);687 if (t != null) {688 t.execute();689 }690 }691 }692 /**693 * Executes the command line as a new process.694 *695 * @param cmd the command to execute696 * @param watchdog - A {@link ExecuteWatchdog} object.697 * @return the exit status of the subprocess or INVALID.698 */699 protected int executeAsForked(CommandlineJava cmd, ExecuteWatchdog watchdog) {700 Execute execute =701 new Execute(702 new TestNGLogSH(703 this, Project.MSG_INFO, Project.MSG_WARN, (m_verbose == null || m_verbose < 5)),704 watchdog);705 execute.setCommandline(cmd.getCommandline());706 execute.setAntRun(getProject());707 if (m_workingDir != null) {708 if (m_workingDir.exists() && m_workingDir.isDirectory()) {709 execute.setWorkingDirectory(m_workingDir);710 } else {711 log("Ignoring invalid working directory : " + m_workingDir, Project.MSG_WARN);712 }713 }714 String[] environment = m_environment.getVariables();715 if (null != environment) {716 for (String envEntry : environment) {717 log("Setting environment variable: " + envEntry, Project.MSG_VERBOSE);718 }719 }720 execute.setEnvironment(environment);721 log(cmd.describeCommand(), Project.MSG_VERBOSE);722 int retVal;723 try {724 retVal = execute.execute();725 } catch (IOException e) {726 throw new BuildException("Process fork failed.", e, getLocation());727 }728 return retVal;729 }730 /** Creates or returns the already created <CODE>CommandlineJava</CODE>. */731 protected CommandlineJava getJavaCommand() {732 if (null == m_javaCommand) {733 m_javaCommand = new CommandlineJava();734 }735 return m_javaCommand;736 }737 /**738 * @return <tt>null</tt> if there is no timeout value, otherwise the watchdog instance.739 * @throws BuildException under unspecified circumstances740 * @since Ant 1.2741 */742 protected ExecuteWatchdog createWatchdog() /*throws BuildException*/ {743 if (m_timeout == null) {744 return null;745 }746 return new ExecuteWatchdog(m_timeout.longValue());747 }748 protected void validateOptions() throws BuildException {749 int suiteCount = getSuiteFileNames().size();750 if (suiteCount == 0751 && m_classFilesets.size() == 0752 && Utils.isStringEmpty(m_methods)753 && ((null == m_testjar) || !m_testjar.isFile())) {754 throw new BuildException("No suites, classes, methods or jar file was specified.");755 }756 if ((null != m_includedGroups) && (m_classFilesets.size() == 0 && suiteCount == 0)) {757 throw new BuildException("No class filesets or xml file sets specified while using groups");758 }759 if (m_onHaltTarget != null) {760 if (!getProject().getTargets().containsKey(m_onHaltTarget)) {761 throw new BuildException("Target " + m_onHaltTarget + " not found in this project");762 }763 }764 }765 private ResourceCollection createResourceCollection(Reference ref) {766 Object o = ref.getReferencedObject();767 if (!(o instanceof ResourceCollection)) {768 throw new BuildException("Only File based ResourceCollections are supported.");769 }770 ResourceCollection rc = (ResourceCollection) o;771 if (!rc.isFilesystemOnly()) {772 throw new BuildException("Only ResourceCollections from local file system are supported.");773 }774 return rc;775 }776 private FileSet appendClassSelector(FileSet fs) {777 FilenameSelector selector = new FilenameSelector();778 selector.setName("**/*.class");779 selector.setProject(getProject());780 fs.appendSelector(selector);781 return fs;782 }783 private File findJar() {784 Class thisClass = getClass();785 String resource = thisClass.getName().replace('.', '/') + ".class";786 URL url = thisClass.getClassLoader().getResource(resource);787 if (null != url) {788 String u = url.toString();789 if (u.startsWith("jar:file:")) {790 int pling = u.indexOf("!");791 String jarName = u.substring(4, pling);792 return new File(fromURI(jarName));793 } else if (u.startsWith("file:")) {794 int tail = u.indexOf(resource);795 String dirName = u.substring(0, tail);796 return new File(fromURI(dirName));797 }798 }799 return null;800 }801 private String fromURI(String uri) {802 URL url = null;803 try {804 url = new URL(uri);805 } catch (MalformedURLException murle) {806 // Gobble exceptions and do nothing.807 }808 if ((null == url) || !("file".equals(url.getProtocol()))) {809 throw new IllegalArgumentException("Can only handle valid file: URIs");810 }811 StringBuilder buf = new StringBuilder(url.getHost());812 if (buf.length() > 0) {813 buf.insert(0, File.separatorChar).insert(0, File.separatorChar);814 }815 String file = url.getFile();816 int queryPos = file.indexOf('?');817 buf.append((queryPos < 0) ? file : file.substring(0, queryPos));818 uri = buf.toString().replace('/', File.separatorChar);819 if ((File.pathSeparatorChar == ';')820 && uri.startsWith("\\")821 && (uri.length() > 2)822 && Character.isLetter(uri.charAt(1))823 && (uri.lastIndexOf(':') > -1)) {824 uri = uri.substring(1);825 }826 StringBuilder sb = new StringBuilder();827 CharacterIterator iter = new StringCharacterIterator(uri);828 for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {829 if (c == '%') {830 char c1 = iter.next();831 if (c1 != CharacterIterator.DONE) {832 int i1 = Character.digit(c1, 16);833 char c2 = iter.next();834 if (c2 != CharacterIterator.DONE) {835 int i2 = Character.digit(c2, 16);836 sb.append((char) ((i1 << 4) + i2));837 }838 }839 } else {840 sb.append(c);841 }842 }843 return sb.toString();844 }845 /**846 * Returns the list of files corresponding to the resource collection847 *848 * @param resources - A list of {@link ResourceCollection}849 * @return the list of files corresponding to the resource collection850 * @throws BuildException851 */852 private List<String> getFiles(List<ResourceCollection> resources) throws BuildException {853 List<String> files = Lists.newArrayList();854 for (ResourceCollection rc : resources) {855 for (Resource o : rc) {856 if (o instanceof FileResource) {857 FileResource fr = ((FileResource) o);858 if (fr.isDirectory()) {859 throw new BuildException("Directory based FileResources are not supported.");860 }861 if (!fr.isExists()) {862 log("'" + fr.toLongString() + "' does not exist", Project.MSG_VERBOSE);863 }864 files.add(fr.getFile().getAbsolutePath());865 } else {866 log("Unsupported Resource type: " + o.toString(), Project.MSG_VERBOSE);867 }868 }869 }870 return files;871 }872 private void dumpCommand(String fileName) {873 log("TESTNG PASSED @" + fileName + " WHICH CONTAINS:", Project.MSG_INFO);874 readAndPrintFile(fileName);875 }876 private void readAndPrintFile(String fileName) {877 try {878 Files.readAllLines(Paths.get(fileName)).forEach(line -> log(" " + line, Project.MSG_INFO));879 } catch (IOException ex) {880 LOGGER.error(ex.getMessage(), ex);881 }882 }883 public void addConfiguredReporter(ReporterConfig reporterConfig) {884 reporterConfigs.add(reporterConfig);885 }886 public void setSkipFailedInvocationCounts(boolean skip) {887 m_skipFailedInvocationCounts = skip;888 }889 public void setXmlPathInJar(String path) {890 m_xmlPathInJar = path;891 }892 /**893 * Add the referenced property set as system properties for the TestNG JVM.894 *895 * @param sysPropertySet A PropertySet of system properties.896 */897 public void addConfiguredPropertySet(PropertySet sysPropertySet) {898 Properties properties = sysPropertySet.getProperties();899 log(900 properties.keySet().size() + " properties found in nested propertyset",901 Project.MSG_VERBOSE);902 for (Object propKeyObj : properties.keySet()) {903 String propKey = (String) propKeyObj;904 Environment.Variable sysProp = new Environment.Variable();905 sysProp.setKey(propKey);906 if (properties.get(propKey) instanceof String) {907 String propVal = (String) properties.get(propKey);908 sysProp.setValue(propVal);909 getJavaCommand().addSysproperty(sysProp);910 log("Added system property " + propKey + " with value " + propVal, Project.MSG_VERBOSE);911 } else {912 log("Ignoring non-String property " + propKey, Project.MSG_WARN);913 }914 }915 }916 @Override917 protected void handleOutput(String output) {918 if (output.startsWith(VerboseReporter.LISTENER_PREFIX)) {919 // send everything from VerboseReporter to verbose level unless log level is > 4920 log(output, m_verbose < 5 ? Project.MSG_VERBOSE : Project.MSG_INFO);921 } else {922 super.handleOutput(output);923 }...

Full Screen

Full Screen

Source:TestNG.java Github

copy

Full Screen

...41 testng.createClasspath().add(mxtest.getUnitTestClasspath());42 testng.addClassfileset(mxtest.getUnitTests());43 44 // Cobertura properties45 testng.addSysproperty(mxtest.getCoberturaFileProperty());46 47 // EMMA properties48 testng.addSysproperty(mxtest.getEmmaFileProperty());49 testng.addSysproperty(mxtest.getEmmaMergeProperty());50 51 // configure properties from Moxie file52 MaxmlMap attributes = mxtest.getBuild().getConfig().getTaskAttributes("testng");53 if (attributes != null) {54 AttributeReflector.setAttributes(mxtest.getProject(), testng, attributes);55 }56 testng.execute();57 }58}...

Full Screen

Full Screen

addSysproperty

Using AI Code Generation

copy

Full Screen

1public class TestNGAntTaskAddSysProperty {2 public static void main(String[] args) {3 TestNGAntTask antTask = new TestNGAntTask();4 antTask.addSysproperty("env", "dev");5 antTask.addSysproperty("env", "qa");6 antTask.addSysproperty("env", "prod");7 antTask.addSysproperty("env", "staging");8 antTask.addSysproperty("env", "stage");9 antTask.addSysproperty("env", "stg");10 antTask.addSysproperty("env", "test");11 antTask.addSysproperty("env", "qa");12 antTask.addSysproperty("env", "uat");13 antTask.addSysproperty("env", "preprod");14 antTask.addSysproperty("env", "pre-prod");15 antTask.addSysproperty("env", "pre_prod");16 antTask.addSysproperty("env", "preprod");17 antTask.addSysproperty("env", "pre-prod");18 antTask.addSysproperty("env", "pre_prod");19 antTask.addSysproperty("env", "preprod");20 antTask.addSysproperty("env", "pre-prod");21 antTask.addSysproperty("env", "pre_prod");22 antTask.addSysproperty("env", "preprod");23 antTask.addSysproperty("env", "pre-prod");24 antTask.addSysproperty("env", "pre_prod");25 antTask.addSysproperty("env", "preprod");26 antTask.addSysproperty("env", "pre-prod");27 antTask.addSysproperty("env", "pre_prod");28 antTask.addSysproperty("env", "preprod");29 antTask.addSysproperty("env", "pre-prod");30 antTask.addSysproperty("env", "pre_prod");31 antTask.addSysproperty("env", "preprod");32 antTask.addSysproperty("env", "pre-prod");33 antTask.addSysproperty("env", "pre_prod");34 antTask.addSysproperty("env", "preprod");35 antTask.addSysproperty("env", "pre-prod");36 antTask.addSysproperty("env", "pre_prod");37 antTask.addSysproperty("env", "preprod");38 antTask.addSysproperty("env", "pre-prod");39 antTask.addSysproperty("

Full Screen

Full Screen

addSysproperty

Using AI Code Generation

copy

Full Screen

1Project project = getProject();2TestNGAntTask antTask = new TestNGAntTask();3antTask.setProject(project);4antTask.setTestClassesDir(new File("test-classes"));5antTask.setTestResultsDir(new File("test-results"));6antTask.setClasspathRef(new Reference(project, "test.classpath"));7antTask.setUseDefaultListeners(false);8antTask.setVerbose(1);9antTask.setListener("org.testng.reporters.JUnitReportReporter");10antTask.addSysproperty("testng.reporter.output", "test-output");11antTask.addSysproperty("testng.reporter.className", "org.testng.reporters.JUnitXMLReporter");12antTask.execute();

Full Screen

Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful