Best Testng code snippet using org.testng.TestNGAntTask.execute
Source:TestNGAntTask.java
...411 *412 * <p>{@inheritDoc}413 */414 @Override415 public void execute() throws BuildException {416 validateOptions();417 CommandlineJava cmd = getJavaCommand();418 cmd.setClassname(m_mainClass);419 if (m_assertEnabled) {420 cmd.createVmArgument().setValue("-ea");421 }422 if (m_delegateCommandSystemProperties) {423 delegateCommandSystemProperties();424 }425 List<String> argv = createArguments();426 String fileName = "";427 FileWriter fw = null;428 BufferedWriter bw = null;429 try {430 File f = File.createTempFile("testng", "");431 fileName = f.getAbsolutePath();432 // If the user asked to see the command, preserve the file433 if (!m_dump) {434 f.deleteOnExit();435 }436 fw = new FileWriter(f);437 bw = new BufferedWriter(fw);438 for (String arg : argv) {439 bw.write(arg);440 bw.newLine();441 }442 bw.flush();443 } catch (IOException e) {444 LOGGER.error(e.getMessage(), e);445 } finally {446 try {447 if (bw != null) {448 bw.close();449 }450 if (fw != null) {451 fw.close();452 }453 } catch (IOException e) {454 LOGGER.error(e.getMessage(), e);455 }456 }457 printDebugInfo(fileName);458 createClasspath().setLocation(findJar());459 cmd.createArgument().setValue("@" + fileName);460 ExecuteWatchdog watchdog = createWatchdog();461 boolean wasKilled = false;462 int exitValue = executeAsForked(cmd, watchdog);463 if (null != watchdog) {464 wasKilled = watchdog.killedProcess();465 }466 actOnResult(exitValue, wasKilled);467 }468 protected List<String> createArguments() {469 List<String> argv = Lists.newArrayList();470 addBooleanIfTrue(argv, CommandLineArgs.JUNIT, mode == Mode.junit);471 addBooleanIfTrue(argv, CommandLineArgs.MIXED, mode == Mode.mixed);472 addBooleanIfTrue(473 argv, CommandLineArgs.SKIP_FAILED_INVOCATION_COUNTS, m_skipFailedInvocationCounts);474 addIntegerIfNotNull(argv, CommandLineArgs.LOG, m_verbose);475 addDefaultListeners(argv);476 addOutputDir(argv);477 addFileIfFile(argv, CommandLineArgs.TEST_JAR, m_testjar);478 addStringIfNotBlank(argv, CommandLineArgs.GROUPS, m_includedGroups);479 addStringIfNotBlank(argv, CommandLineArgs.EXCLUDED_GROUPS, m_excludedGroups);480 addFilesOfRCollection(argv, CommandLineArgs.TEST_CLASS, m_classFilesets);481 addListOfStringIfNotEmpty(argv, CommandLineArgs.LISTENER, m_listeners);482 addListOfStringIfNotEmpty(argv, CommandLineArgs.METHOD_SELECTORS, m_methodselectors);483 addStringIfNotNull(argv, CommandLineArgs.OBJECT_FACTORY, m_objectFactory);484 addStringIfNotNull(argv, CommandLineArgs.TEST_RUNNER_FACTORY, m_testRunnerFactory);485 addStringIfNotNull(argv, CommandLineArgs.PARALLEL, m_parallelMode);486 addStringIfNotNull(argv, CommandLineArgs.CONFIG_FAILURE_POLICY, m_configFailurePolicy);487 addBooleanIfTrue(argv, CommandLineArgs.RANDOMIZE_SUITES, m_randomizeSuites);488 addStringIfNotNull(argv, CommandLineArgs.THREAD_COUNT, m_threadCount);489 addStringIfNotNull(argv, CommandLineArgs.DATA_PROVIDER_THREAD_COUNT, m_dataproviderthreadCount);490 addStringIfNotBlank(argv, CommandLineArgs.SUITE_NAME, m_suiteName);491 addStringIfNotBlank(argv, CommandLineArgs.TEST_NAME, m_testName);492 addStringIfNotBlank(argv, CommandLineArgs.TEST_NAMES, m_testNames);493 addStringIfNotBlank(argv, CommandLineArgs.METHODS, m_methods);494 addReporterConfigs(argv);495 addIntegerIfNotNull(argv, CommandLineArgs.SUITE_THREAD_POOL_SIZE, m_suiteThreadPoolSize);496 addStringIfNotNull(argv, CommandLineArgs.XML_PATH_IN_JAR, m_xmlPathInJar);497 addXmlFiles(argv);498 return argv;499 }500 private void addDefaultListeners(List<String> argv) {501 if (m_useDefaultListeners != null) {502 String useDefaultListeners = "false";503 if ("yes".equalsIgnoreCase(m_useDefaultListeners)504 || "true".equalsIgnoreCase(m_useDefaultListeners)) {505 useDefaultListeners = "true";506 }507 argv.add(CommandLineArgs.USE_DEFAULT_LISTENERS);508 argv.add(useDefaultListeners);509 }510 }511 private void addOutputDir(List<String> argv) {512 if (null != m_outputDir) {513 if (!m_outputDir.exists()) {514 m_outputDir.mkdirs();515 }516 if (m_outputDir.isDirectory()) {517 argv.add(CommandLineArgs.OUTPUT_DIRECTORY);518 argv.add(m_outputDir.getAbsolutePath());519 } else {520 throw new BuildException("Output directory is not a directory: " + m_outputDir);521 }522 }523 }524 private void addReporterConfigs(List<String> argv) {525 for (ReporterConfig reporterConfig : reporterConfigs) {526 argv.add(CommandLineArgs.REPORTER);527 argv.add(reporterConfig.serialize());528 }529 }530 private void addFilesOfRCollection(531 List<String> argv, String name, List<ResourceCollection> resources) {532 addArgumentsIfNotEmpty(argv, name, getFiles(resources), ",");533 }534 private void addListOfStringIfNotEmpty(List<String> argv, String name, List<String> arguments) {535 addArgumentsIfNotEmpty(argv, name, arguments, ";");536 }537 private void addArgumentsIfNotEmpty(538 List<String> argv, String name, List<String> arguments, String separator) {539 if (arguments != null && !arguments.isEmpty()) {540 argv.add(name);541 String value = Utils.join(arguments, separator);542 argv.add(value);543 }544 }545 private void addFileIfFile(List<String> argv, String name, File file) {546 if ((null != file) && file.isFile()) {547 argv.add(name);548 argv.add(file.getAbsolutePath());549 }550 }551 private void addBooleanIfTrue(List<String> argv, String name, Boolean value) {552 if (TRUE.equals(value)) {553 argv.add(name);554 }555 }556 private void addIntegerIfNotNull(List<String> argv, String name, Integer value) {557 if (value != null) {558 argv.add(name);559 argv.add(value.toString());560 }561 }562 private void addStringIfNotNull(List<String> argv, String name, String value) {563 if (value != null) {564 argv.add(name);565 argv.add(value);566 }567 }568 private void addStringIfNotBlank(List<String> argv, String name, String value) {569 if (isStringNotBlank(value)) {570 argv.add(name);571 argv.add(value);572 }573 }574 private void addXmlFiles(List<String> argv) {575 for (String file : getSuiteFileNames()) {576 argv.add(file);577 }578 }579 /** @return the list of the XML file names. This method can be overridden by subclasses. */580 protected List<String> getSuiteFileNames() {581 List<String> result = Lists.newArrayList();582 for (String file : getFiles(m_xmlFilesets)) {583 result.add(file);584 }585 return result;586 }587 private void delegateCommandSystemProperties() {588 // Iterate over command-line args and pass them through as sysproperty589 // exclude any built-in properties that start with "ant."590 for (Object propKey : getProject().getUserProperties().keySet()) {591 String propName = (String) propKey;592 String propVal = getProject().getUserProperty(propName);593 if (propName.startsWith("ant.")) {594 log("Excluding ant property: " + propName + ": " + propVal, Project.MSG_DEBUG);595 } else {596 log("Including user property: " + propName + ": " + propVal, Project.MSG_DEBUG);597 Environment.Variable var = new Environment.Variable();598 var.setKey(propName);599 var.setValue(propVal);600 addSysproperty(var);601 }602 }603 }604 private void printDebugInfo(String fileName) {605 if (m_dumpSys) {606 debug("* SYSTEM PROPERTIES *");607 Properties props = System.getProperties();608 Enumeration en = props.propertyNames();609 while (en.hasMoreElements()) {610 String key = (String) en.nextElement();611 debug(key + ": " + props.getProperty(key));612 }613 debug("");614 }615 if (m_dumpEnv) {616 String[] vars = m_environment.getVariables();617 if (null != vars && vars.length > 0) {618 debug("* ENVIRONMENT *");619 for (String v : vars) {620 debug(v);621 }622 debug("");623 }624 }625 if (m_dump) {626 dumpCommand(fileName);627 }628 }629 private void debug(String message) {630 log("[TestNGAntTask] " + message, Project.MSG_DEBUG);631 }632 protected void actOnResult(int exitValue, boolean wasKilled) {633 if (exitValue == -1) {634 executeHaltTarget(exitValue);635 throw new BuildException("an error occurred when running TestNG tests");636 }637 if ((exitValue & ExitCode.HAS_NO_TEST) == ExitCode.HAS_NO_TEST) {638 if (m_haltOnFailure) {639 executeHaltTarget(exitValue);640 throw new BuildException("No tests were run");641 } else {642 if (null != m_failurePropertyName) {643 getProject().setNewProperty(m_failurePropertyName, "true");644 }645 log("TestNG haven't found any tests to be run", Project.MSG_DEBUG);646 }647 }648 boolean failed = (ExitCode.hasFailure(exitValue)) || wasKilled;649 if (failed) {650 final String msg = wasKilled ? "The tests timed out and were killed." : "The tests failed.";651 if (m_haltOnFailure) {652 executeHaltTarget(exitValue);653 throw new BuildException(msg);654 } else {655 if (null != m_failurePropertyName) {656 getProject().setNewProperty(m_failurePropertyName, "true");657 }658 log(msg, Project.MSG_INFO);659 }660 }661 if (ExitCode.hasSkipped(exitValue)) {662 if (m_haltOnSkipped) {663 executeHaltTarget(exitValue);664 throw new BuildException("There are TestNG SKIPPED tests");665 } else {666 if (null != m_skippedPropertyName) {667 getProject().setNewProperty(m_skippedPropertyName, "true");668 }669 log("There are TestNG SKIPPED tests", Project.MSG_DEBUG);670 }671 }672 if (ExitCode.hasFailureWithinSuccessPercentage(exitValue)) {673 if (m_haltOnFSP) {674 executeHaltTarget(exitValue);675 throw new BuildException("There are TestNG FAILED WITHIN SUCCESS PERCENTAGE tests");676 } else {677 if (null != m_fspPropertyName) {678 getProject().setNewProperty(m_fspPropertyName, "true");679 }680 log("There are TestNG FAILED WITHIN SUCCESS PERCENTAGE tests", Project.MSG_DEBUG);681 }682 }683 }684 /** Executes the target, if any, that user designates executing before failing the test */685 private void executeHaltTarget(int exitValue) {686 if (m_onHaltTarget != null) {687 if (m_outputDir != null) {688 getProject().setProperty("testng.outputdir", m_outputDir.getAbsolutePath());689 }690 getProject().setProperty("testng.returncode", String.valueOf(exitValue));691 Target t = getProject().getTargets().get(m_onHaltTarget);692 if (t != null) {693 t.execute();694 }695 }696 }697 /**698 * Executes the command line as a new process.699 *700 * @param cmd the command to execute701 * @param watchdog - A {@link ExecuteWatchdog} object.702 * @return the exit status of the subprocess or INVALID.703 */704 protected int executeAsForked(CommandlineJava cmd, ExecuteWatchdog watchdog) {705 Execute execute =706 new Execute(707 new TestNGLogSH(708 this, Project.MSG_INFO, Project.MSG_WARN, (m_verbose == null || m_verbose < 5)),709 watchdog);710 execute.setCommandline(cmd.getCommandline());711 execute.setAntRun(getProject());712 if (m_workingDir != null) {713 if (m_workingDir.exists() && m_workingDir.isDirectory()) {714 execute.setWorkingDirectory(m_workingDir);715 } else {716 log("Ignoring invalid working directory : " + m_workingDir, Project.MSG_WARN);717 }718 }719 String[] environment = m_environment.getVariables();720 if (null != environment) {721 for (String envEntry : environment) {722 log("Setting environment variable: " + envEntry, Project.MSG_VERBOSE);723 }724 }725 execute.setEnvironment(environment);726 log(cmd.describeCommand(), Project.MSG_VERBOSE);727 int retVal;728 try {729 retVal = execute.execute();730 } catch (IOException e) {731 throw new BuildException("Process fork failed.", e, getLocation());732 }733 return retVal;734 }735 /** Creates or returns the already created <CODE>CommandlineJava</CODE>. */736 protected CommandlineJava getJavaCommand() {737 if (null == m_javaCommand) {738 m_javaCommand = new CommandlineJava();739 }740 return m_javaCommand;741 }742 /**743 * @return <tt>null</tt> if there is no timeout value, otherwise the watchdog instance....
Source:MxTest.java
...132 return v;133 } 134 135 @Override136 public void execute() throws BuildException {137 /*138 * Prepare all variables and state.139 */140 141 Build build = getBuild();142 BuildConfig config = build.getConfig();143 144 // generate unit test info into build/tests145 unitTestOutputDirectory = new File(config.getOutputDirectory(null), "tests");146 FileUtils.delete(unitTestOutputDirectory);147 unitTestOutputDirectory.mkdirs();148 // generate unit test info into target/tests149 testReports = new File(config.getReportsTargetDirectory(), "tests");150 FileUtils.delete(testReports);151 testReports.mkdirs();152 153 // instrument classes for code coverages into build/instrumented-classes154 instrumentedBuild = new File(config.getOutputDirectory(null), "instrumented-classes");155 FileUtils.delete(instrumentedBuild);156 instrumentedBuild.mkdirs();157 // generate code coverage report into target/coverage158 coverageReports = new File(config.getReportsTargetDirectory(), "coverage");159 FileUtils.delete(coverageReports);160 coverageReports.mkdirs();161 // delete Corbertura metadata162 coberturaData = new File(config.getOutputDirectory(null), "cobertura.ser");163 coberturaData.delete();164 // delete EMMA metadata165 emmaData = new File(config.getOutputDirectory(null), "metadata.emma");166 emmaData.delete();167 // delete JaCoCo metadata168 jacocoData = new File(config.getOutputDirectory(null), "jacoco.exec");169 jacocoData.delete();170 classesDirectory = config.getOutputDirectory(Scope.compile);171 testClassesDirectory = config.getOutputDirectory(Scope.test);172 // define the test class fileset173 unitTests = new FileSet();174 unitTests.setProject(getProject());175 unitTests.setDir(testClassesDirectory);176 MaxmlMap attributes = config.getTaskAttributes(getTaskName());177 failureProperty = attributes.getString("failureProperty", "unit.test.failed");178 failOnError = attributes.getBoolean("failOnError", false);179 unitTests.createInclude().setName(attributes.getString("include", "**/*Test.class"));180 // classpath for tests181 // instrumented classes, unit test classes, and unit test libraries182 unitTestClasspath = new Path(getProject());183 unitTestClasspath.createPathElement().setPath(instrumentedBuild.getAbsolutePath());184 unitTestClasspath.createPath().setRefid(new Reference(getProject(), Key.testClasspath.referenceId()));185 unitTestClasspath.createPath().setRefid(new Reference(getProject(), Key.buildClasspath.referenceId()));186 unitTestClasspath.createPathElement().setPath(testClassesDirectory.getAbsolutePath());187 188 // log the unit test classpath to the console in debug mode 189 build.getConsole().debug("unit test classpath");190 for (String element : unitTestClasspath.toString().split(File.pathSeparator)) {191 build.getConsole().debug(1, element);192 }193 /*194 * Do the work.195 */196 197 // compile the code and unit test classes198 MxJavac compile = new MxJavac();199 compile.setProject(getProject());200 compile.setScope(Scope.test.name());201 compile.execute();202 // instrument code classes203 if (hasClass("net.sourceforge.cobertura.ant.InstrumentTask")) { 204 Cobertura.instrument(this);205 } else if (hasClass("com.vladium.emma.emmaTask")) {206 Emma.instrument(this);207 } else if (hasClass("org.jacoco.ant.AbstractCoverageTask")) {208 // jacoco wraps unit test tasks209 } else {210 build.getConsole().warn("SKIPPING code-coverage!");211 build.getConsole().warn("add \"- build jacoco\", \"- build cobertura\", or \"- build emma\" to your dependencies for code-coverage.");212 }213 214 // optional jvmarg for running unit tests215 String jvmarg = null;216 if (hasClass("org.jacoco.ant.AbstractCoverageTask")) {217 jvmarg = Jacoco.newJvmarg(this);218 }219 220 // execute unit tests221 if (hasClass("org.testng.TestNGAntTask")) { 222 TestNG.test(this, jvmarg);223 } else if (hasClass("junit.framework.Test")) {224 JUnit.test(this, jvmarg);225 } else {226 build.getConsole().warn("SKIPPING unit tests!");227 build.getConsole().warn("add \"- test junit\" or \"- test testng\" to your dependencies to execute unit tests.");228 }229 230 // generate code coverage reports231 if (hasClass("net.sourceforge.cobertura.ant.ReportTask")) {232 Cobertura.report(this);233 } else if (hasClass("com.vladium.emma.report.reportTask")) {234 Emma.report(this);235 } else if (hasClass("org.jacoco.ant.ReportTask")) {236 Jacoco.report(this);237 }238 239 if ((getProject().getProperty(getFailureProperty()) != null) && failOnError) {240 throw new MoxieException("{0} has failed unit tests! Build aborted!", build.getPom().getArtifactId());241 }...
Source:checkout_page.java
...82 Driver.implicitwait();83 //btnContinueCheck1.isEnabled();84 btnContinueSummary.isEnabled();85 JavascriptExecutor js = (JavascriptExecutor) driver;86 js.executeScript ("arguments [0] .click ();", btnContinueSummary);87 js.executeScript("alert('Probando...');");88 }89 public void SecAddress(){90 Driver.implicitwait();91 btnContinueAddress.isEnabled();92 JavascriptExecutor js = (JavascriptExecutor) driver;93 js.executeScript ("arguments [0] .click ();", btnContinueAddress);94 js.executeScript("alert('Probando...');");95 //VerifContSummary.isDisplayed();96 // auxBtn3.isDisplayed();97 // Driver.implicitwait();98 //Driver.customWait_clickable(btnContinueCheck3);99 // btnContinueCheck3.isSelected();100 // btnContinueCheck3.click();101 // Driver.implicitwait();102 }103 public void SecShipping(){104 Driver.customWait_clickable(VerifContSummary);105 SecShipping.isDisplayed();106 Driver.customWait_clickable(checkTerminos);107 Driver.customWait_clickable(btnContinueCheck4);108 checkTerminos.isSelected();...
Source:AutomationRunner.java
...62 if (args.length>2) {63 browser=args[2];64 //setProperty("Config.properties", "browser",args[2]);65 }66 List<Class> executeClassList = Lists.newArrayList();67 for (String c : testClasses) {68 69 70 for (Class<?> classInstance : classesList) {71 String packageName = classInstance.getPackage().getName();72 if (classInstance.getName().contains(c)) {73 executeClassList.add(classInstance);74 }75 }76 }77 testNG = new TestNG();78 testNG.setTestClasses(executeClassList.toArray(new Class[0]));79 testNG.setGroups(testGroups);80 testNG.run();81 82 //}83 84 /*testNG = new TestNG();85 testNG.setTestClasses(new Class[] {testClasses[i].class});86 testNG.setGroups("Formula Builder");87 testNG.run();*/8889 }9091}
Source:TestNG.java
...52 MaxmlMap attributes = mxtest.getBuild().getConfig().getTaskAttributes("testng");53 if (attributes != null) {54 AttributeReflector.setAttributes(mxtest.getProject(), testng, attributes);55 }56 testng.execute();57 }58}...
execute
Using AI Code Generation
1import org.testng.TestNGAntTask2import org.apache.tools.ant.Project3import org.apache.tools.ant.types.Path4import org.apache.tools.ant.types.FileSet5def testng = new TestNGAntTask()6testng.setProject(new Project())7testng.setTestClassesDir(new Path(new Project(), "target/test-classes"))8testng.setUseDefaultListeners(false)9testng.setTestClasses(new FileSet(new Project(), new Path(new Project(), "target/test-classes/testng.xml")))10testng.execute()
execute
Using AI Code Generation
1import org.testng.TestNGAntTask;2import org.apache.tools.ant.Project;3import org.apache.tools.ant.BuildException;4public class TestNGAntTaskExample {5 public static void main(String[] args) {6 Project project = new Project();7 project.init();8 TestNGAntTask testNGAntTask = new TestNGAntTask();9 testNGAntTask.setProject(project);10 testNGAntTask.setTestClassesDir("test-classes");11 testNGAntTask.setTestOutputDir("test-output");12 testNGAntTask.setSuiteXmlFiles("testng.xml");13 try {14 testNGAntTask.execute();15 } catch (BuildException e) {16 e.printStackTrace();17 }18 }19}
execute
Using AI Code Generation
1import org.testng.TestNGAntTask2import org.apache.tools.ant.Project3import org.apache.tools.ant.types.Path4import org.apache.tools.ant.types.FileSet5def testNGAntTask=new TestNGAntTask()6testNGAntTask.setProject(new Project())7testNGAntTask.setTestClassesDir(new Path(new Project(), "target/test-classes"))8testNGAntTask.setClasspath(new Path(new Project(), "target/test-classes"))9testNGAntTask.setParallel("classes")10testNGAntTask.setThreadCount(2)11testNGAntTask.setUseDefaultListeners(false)12testNGAntTask.setVerbose(1)13testNGAntTask.setTest("com.example.test.Test1")14testNGAntTask.setReporter("org.uncommons.reportng.HTMLReporter")15testNGAntTask.setReporter("org.uncommons.reportng.JUnitXMLReporter")16testNGAntTask.setReporter("org.uncommons.reportng.EmailableReporter")17testNGAntTask.setReporter("org.uncommons.reportng.JUnitReporter")18testNGAntTask.execute()19import org.testng.TestNG20import org.testng.xml.XmlSuite21import org.testng.xml.XmlTest22import org.testng.xml.XmlClass23import org.testng.xml.XmlInclude24import org.testng.xml.XmlSuite.ParallelMode25import org.testng.xml.XmlSuite.FailurePolicy26def xmlSuite=new XmlSuite()27xmlSuite.setName("Suite")28xmlSuite.setParallel(ParallelMode.CLASSES)29xmlSuite.setThreadCount(2)30xmlSuite.setVerbose(1)31xmlSuite.setVerbose(2)32xmlSuite.setVerbose(3)33xmlSuite.setVerbose(4)34xmlSuite.setVerbose(5)35xmlSuite.setVerbose(6)36xmlSuite.setVerbose(7)37xmlSuite.setVerbose(8)38xmlSuite.setVerbose(9)39xmlSuite.setVerbose(10)40xmlSuite.setVerbose(11)41xmlSuite.setVerbose(12)42xmlSuite.setVerbose(13)43xmlSuite.setVerbose(14)44xmlSuite.setVerbose(15)45xmlSuite.setVerbose(16)46xmlSuite.setVerbose(17)47xmlSuite.setVerbose(18)48xmlSuite.setVerbose(19)49xmlSuite.setVerbose(20)50xmlSuite.setVerbose(21)51xmlSuite.setVerbose(22)52xmlSuite.setVerbose(23)53xmlSuite.setVerbose(24)54xmlSuite.setVerbose(25)55xmlSuite.setVerbose(26)56xmlSuite.setVerbose(27)
execute
Using AI Code Generation
1import org.testng.TestNGAntTask2import org.apache.tools.ant.Project3import org.apache.tools.ant.BuildException4import org.apache.tools.ant.BuildEvent5import org.apache.tools.ant.BuildListener6import org.apache.tools.ant.types.FileSet7import org.apache.tools.ant.types.Path8import org.apache.tools.ant.types.resources.FileResource9import org.apache.tools.ant.types.resources.FileResourceIterator10import org.apache.tools.ant.types.resources.FileResourceIteratorFactory11import org.apache.tools.ant.types.resources.Union12import org.apache.tools.ant.types.resources.selectors.ResourceSelector13import org.apache.tools.ant.types.resources.selectors.ResourceSelectorContainer14import org.apache.tools.ant.types.selectors.SelectorUtils15import org.apache.tools.ant.types.selectors.SelectorUtils.Tokenizer16import java.util.regex.Pattern17def testng = new TestNGAntTask()18def project = new Project()19project.init()20testng.setProject(project)21testng.setTaskName('testng')22testng.setFork(false)23testng.setUseDefaultListeners(false)24testng.setHaltonfailure(true)25testng.setSuiteXmlFiles(new File('testng.xml').absolutePath)26def listener = new BuildListener() {27 void messageLogged(BuildEvent event) {28 }29 void targetStarted(BuildEvent event) {30 }31 void taskStarted(BuildEvent event) {32 }33 void taskFinished(BuildEvent event) {34 }35 void targetFinished(BuildEvent event) {36 }37 void buildStarted(BuildEvent event) {38 }39 void buildFinished(BuildEvent event) {40 }41}42project.addBuildListener(listener)43testng.execute()
execute
Using AI Code Generation
1import org.testng.TestNGAntTask2import java.io.File3import java.util.ArrayList4import java.util.List5def ant = new AntBuilder()6ant.taskdef(name: 'testng', classname: 'org.testng.TestNGAntTask', classpath: 'testng.jar')7def testng = new TestNGAntTask()8def testngXmlFiles = new ArrayList<File>()9def testngXmlDir = new File('src/test/resources/testng')10testngXmlDir.eachFileMatch(11 { testngXmlFiles.add(it) }12testng.setTestSuites(testngXmlFiles)13testng.execute()
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.
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.
Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!