How to use getFailedTests method of org.testng.TestListenerAdapter class

Best Testng code snippet using org.testng.TestListenerAdapter.getFailedTests

Source:ArtifactCollectorTest.java Github

copy

Full Screen

...28 testNG.setGroups("testPassed");29 testNG.run();30 31 assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");32 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");33 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");34 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");35 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");36 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");37 38 ITestResult result = tla.getPassedTests().get(0);39 assertNull(UnitTestArtifact.getCaptureState(result), "Artifact provider capture state should be 'null'");40 assertNull(UnitTestCapture.getArtifactPath(result), "Artifact capture should not have been requested");41 }42 43 @Test44 public void verifyCaptureOnFailure() {45 46 ListenerChain lc = new ListenerChain();47 TestListenerAdapter tla = new TestListenerAdapter();48 49 TestNG testNG = new TestNG();50 testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});51 testNG.addListener((ITestNGListener) lc);52 testNG.addListener((ITestNGListener) tla);53 testNG.setGroups("testFailed");54 testNG.run();55 56 assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");57 assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");58 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");59 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");60 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");61 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");62 63 ITestResult result = tla.getFailedTests().get(0);64 assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");65 assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");66 }67 68 @Test69 public void verifyCanNotCapture() {70 71 ListenerChain lc = new ListenerChain();72 TestListenerAdapter tla = new TestListenerAdapter();73 74 TestNG testNG = new TestNG();75 testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});76 testNG.addListener((ITestNGListener) lc);77 testNG.addListener((ITestNGListener) tla);78 testNG.setGroups("canNotCapture");79 testNG.run();80 81 assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");82 assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");83 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");84 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");85 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");86 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");87 88 ITestResult result = tla.getFailedTests().get(0);89 assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAN_NOT_CAPTURE, "Incorrect artifact provider capture state");90 assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");91 }92 93 @Test94 public void verifyWillNotCapture() {95 96 ListenerChain lc = new ListenerChain();97 TestListenerAdapter tla = new TestListenerAdapter();98 99 TestNG testNG = new TestNG();100 testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});101 testNG.addListener((ITestNGListener) lc);102 testNG.addListener((ITestNGListener) tla);103 testNG.setGroups("willNotCapture");104 testNG.run();105 106 assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");107 assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");108 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");109 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");110 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");111 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");112 113 ITestResult result = tla.getFailedTests().get(0);114 assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_FAILED, "Incorrect artifact provider capture state");115 assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");116 }117 118 @Test119 public void verifyOnDemandCapture() {120 121 ListenerChain lc = new ListenerChain();122 TestListenerAdapter tla = new TestListenerAdapter();123 124 TestNG testNG = new TestNG();125 testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});126 testNG.addListener((ITestNGListener) lc);127 testNG.addListener((ITestNGListener) tla);128 testNG.setGroups("onDemandCapture");129 testNG.run();130 131 assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");132 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");133 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");134 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");135 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");136 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");137 138 ITestResult result = tla.getPassedTests().get(0);139 assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");140 assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");141 }142} ...

Full Screen

Full Screen

Source:ExecutionFlowControllerTest.java Github

copy

Full Screen

...25 testNG.addListener((ITestNGListener) efc);26 testNG.addListener((ITestNGListener) tla);27 testNG.run();28 29 assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");30 assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");31 32 assertEquals(tla.getPassedTests().size(), 2, "Incorrect passed test count");33 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");34 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");35 36 assertEquals(HappyPathClass.fromBefore, HappyPathClass.VALUE, "Incorrect [before] value");37 assertEquals(HappyPathClass.fromMethod, HappyPathClass.VALUE, "Incorrect [method] value");38 assertEquals(HappyPathClass.fromAfter, HappyPathClass.VALUE, "Incorrect [after] value");39 40 }41 42 @Test43 public void testSkipFromBefore() {44 45 ExecutionFlowController efc = new ExecutionFlowController();46 TestListenerAdapter tla = new TestListenerAdapter();47 48 TestNG testNG = new TestNG();49 testNG.setTestClasses(new Class[]{SkipFromBefore.class});50 testNG.addListener((ITestNGListener) efc);51 testNG.addListener((ITestNGListener) tla);52 testNG.setConfigFailurePolicy(FailurePolicy.CONTINUE);53 testNG.run();54 55 assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");56 assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");57 58 assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");59 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");60 assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration skip count");61 assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");62 ITestResult methodResult = tla.getSkippedTests().get(0);63 assertEquals(methodResult.getName(), "testMethod", "Incorrect skipped test name");64 65 assertEquals(SkipFromBefore.fromBefore, SkipFromBefore.VALUE, "Incorrect [before] value");66 assertEquals(methodResult.getAttribute(SkipFromBefore.ATTRIBUTE), SkipFromBefore.VALUE, "Incorrect [method] value");67 assertEquals(SkipFromBefore.fromAfter, SkipFromBefore.VALUE, "Incorrect [after] value");68 69 }70 71 @Test72 public void testSkipFromMethod() {73 74 ExecutionFlowController efc = new ExecutionFlowController();75 TestListenerAdapter tla = new TestListenerAdapter();76 77 TestNG testNG = new TestNG();78 testNG.setTestClasses(new Class[]{SkipFromMethod.class});79 testNG.addListener((ITestNGListener) efc);80 testNG.addListener((ITestNGListener) tla);81 testNG.run();82 83 assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");84 assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");85 86 assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");87 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");88 assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");89 assertEquals(tla.getSkippedTests().get(0).getName(), "testMethod", "Incorrect skipped test name");90 91 assertEquals(SkipFromMethod.fromBefore, SkipFromMethod.VALUE, "Incorrect [before] value");92 assertEquals(SkipFromMethod.fromMethod, SkipFromMethod.VALUE, "Incorrect [method] value");93 assertEquals(SkipFromMethod.fromAfter, SkipFromMethod.VALUE, "Incorrect [after] value");94 95 }96 97 @Test98 public void testMethodListenerExtension() {99 100 ExecutionFlowController efc = new ExecutionFlowController();101 TestListenerAdapter tla = new TestListenerAdapter();102 103 TestNG testNG = new TestNG();104 testNG.setTestClasses(new Class[]{MethodListenerExtension.class});105 testNG.addListener((ITestNGListener) efc);106 testNG.addListener((ITestNGListener) tla);107 testNG.run();108 109 assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");110 assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");111 112 assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");113 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");114 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");115 116 assertTrue(MethodListenerExtension.beforeMethodBefore, "Incorrect [beforeMethod] 'before' value");117 assertTrue(MethodListenerExtension.testMethodBefore, "Incorrect [testMethod] 'before' value");118 assertTrue(MethodListenerExtension.afterMethodBefore, "Incorrect [afterMethod] 'before' value");119 assertTrue(MethodListenerExtension.beforeMethodAfter, "Incorrect [beforeMethod] 'after' value");120 assertTrue(MethodListenerExtension.testMethodAfter, "Incorrect [testMethod] 'after' value");121 assertTrue(MethodListenerExtension.afterMethodAfter, "Incorrect [afterMethod] 'after' value");122 123 }124125} ...

Full Screen

Full Screen

Source:NameTest.java Github

copy

Full Screen

...15 TestNG tng = create(SimpleITestSample.class);16 TestListenerAdapter adapter = new TestListenerAdapter();17 tng.addListener(adapter);18 tng.run();19 Assert.assertTrue(adapter.getFailedTests().isEmpty());20 Assert.assertTrue(adapter.getSkippedTests().isEmpty());21 Assert.assertEquals(adapter.getPassedTests().size(), 1);22 ITestResult result = adapter.getPassedTests().get(0);23 Assert.assertEquals(result.getMethod().getMethodName(), "test");24 Assert.assertEquals(result.getName(), "NAME");25 Assert.assertEquals(result.getTestName(), "NAME");26 }27 @Test28 public void itestTestWithXml() {29 TestNG tng = createTests("suite", SimpleITestSample.class);30 TestListenerAdapter adapter = new TestListenerAdapter();31 tng.addListener(adapter);32 tng.run();33 Assert.assertTrue(adapter.getFailedTests().isEmpty());34 Assert.assertTrue(adapter.getSkippedTests().isEmpty());35 Assert.assertEquals(adapter.getPassedTests().size(), 1);36 ITestResult result = adapter.getPassedTests().get(0);37 Assert.assertEquals(result.getMethod().getMethodName(), "test");38 Assert.assertEquals(result.getName(), "NAME");39 Assert.assertEquals(result.getTestName(), "NAME");40 }41 @Test42 public void testNameTest() {43 TestNG tng = create(NameSample.class);44 TestListenerAdapter adapter = new TestListenerAdapter();45 tng.addListener(adapter);46 tng.run();47 Assert.assertTrue(adapter.getFailedTests().isEmpty());48 Assert.assertTrue(adapter.getSkippedTests().isEmpty());49 Assert.assertEquals(adapter.getPassedTests().size(), 1);50 ITestResult result = adapter.getPassedTests().get(0);51 Assert.assertEquals(result.getMethod().getMethodName(), "test");52 Assert.assertEquals(result.getName(), "NAME");53 Assert.assertEquals(result.getTestName(), "NAME");54 }55 @Test56 public void testNameTestWithXml() {57 TestNG tng = createTests("suite", NameSample.class);58 TestListenerAdapter adapter = new TestListenerAdapter();59 tng.addListener(adapter);60 tng.run();61 Assert.assertTrue(adapter.getFailedTests().isEmpty());62 Assert.assertTrue(adapter.getSkippedTests().isEmpty());63 Assert.assertEquals(adapter.getPassedTests().size(), 1);64 ITestResult result = adapter.getPassedTests().get(0);65 Assert.assertEquals(result.getMethod().getMethodName(), "test");66 Assert.assertEquals(result.getName(), "NAME");67 Assert.assertEquals(result.getTestName(), "NAME");68 }69 @Test70 public void noNameTest() {71 TestNG tng = create(NoNameSample.class);72 TestListenerAdapter adapter = new TestListenerAdapter();73 tng.addListener(adapter);74 tng.run();75 Assert.assertTrue(adapter.getFailedTests().isEmpty());76 Assert.assertTrue(adapter.getSkippedTests().isEmpty());77 Assert.assertEquals(adapter.getPassedTests().size(), 1);78 ITestResult result = adapter.getPassedTests().get(0);79 Assert.assertEquals(result.getMethod().getMethodName(), "test");80 Assert.assertEquals(result.getName(), "test");81 Assert.assertEquals(result.getTestName(), null);82 }83 @Test84 public void noNameTestWithXml() {85 TestNG tng = createTests("suite", NoNameSample.class);86 TestListenerAdapter adapter = new TestListenerAdapter();87 tng.addListener(adapter);88 tng.run();89 Assert.assertTrue(adapter.getFailedTests().isEmpty());90 Assert.assertTrue(adapter.getSkippedTests().isEmpty());91 Assert.assertEquals(adapter.getPassedTests().size(), 1);92 ITestResult result = adapter.getPassedTests().get(0);93 Assert.assertEquals(result.getMethod().getMethodName(), "test");94 Assert.assertEquals(result.getName(), "test");95 Assert.assertEquals(result.getTestName(), null);96 }97 @Test98 public void complexITestTest() {99 TestNG tng = create(ITestSample.class);100 TestListenerAdapter adapter = new TestListenerAdapter();101 tng.addListener(adapter);102 tng.run();103 Assert.assertTrue(adapter.getFailedTests().isEmpty());104 Assert.assertTrue(adapter.getSkippedTests().isEmpty());105 Assert.assertEquals(adapter.getPassedTests().size(), 5);106 List<String> testNames = new ArrayList<>(Arrays.asList("test1", "test2", "test3", "test4", "test5"));107 for (ITestResult testResult : adapter.getPassedTests()) {108 Assert.assertTrue(testNames.remove(testResult.getName()),109 "Duplicate test names " + getNames(adapter.getPassedTests()));110 }111 Assert.assertEquals(testNames, Collections.emptyList());112 }113 private static List<String> getNames(List<ITestResult> results) {114 List<String> names = new ArrayList<>(results.size());115 for (ITestResult result : results) {116 names.add(result.getName());117 }...

Full Screen

Full Screen

Source:TestngListener.java Github

copy

Full Screen

...62 }63 /*64 * (non-Javadoc)65 * 66 * @see org.testng.TestListenerAdapter#getFailedTests()67 */68 @Override69 public List<ITestResult> getFailedTests() {70 // TODO Auto-generated method stub71 return super.getFailedTests();72 }73 /*74 * (non-Javadoc)75 * 76 * @see org.testng.TestListenerAdapter#getPassedTests()77 */78 @Override79 public List<ITestResult> getPassedTests() {80 // TODO Auto-generated method stub81 return super.getPassedTests();82 }83 /*84 * (non-Javadoc)85 * ...

Full Screen

Full Screen

Source:MixedTest.java Github

copy

Full Screen

...22 };23 TestListenerAdapter tla = new TestListenerAdapter();24 TestNG.privateMain(argv, tla);25 Assert.assertEquals(tla.getPassedTests().size(), 5); //2 from junit3test1, 2 from junit4test1, 0 from testngtest1 (no groups), 1 from testnggroups (1 is included, 1 is excluded)26 Assert.assertEquals(tla.getFailedTests().size(), 0);27 }28 @Test29 public void mixedClasses() {30 String[] argv = {31 "-d", OutputDirectoryPatch.getOutputDirectory(),32 "-log", "0",33 "-mixed",34 "-testclass", "test.mixed.JUnit3Test1,test.mixed.JUnit4Test1,test.mixed.TestNGTest1"35 };36 TestListenerAdapter tla = new TestListenerAdapter();37 TestNG.privateMain(argv, tla);38 Assert.assertEquals(tla.getPassedTests().size(), 6);39 Assert.assertEquals(tla.getFailedTests().size(), 0);40 }41 @Test42 public void mixedMethods() {43 String[] argv = {44 "-d", OutputDirectoryPatch.getOutputDirectory(),45 "-mixed",46 "-log", "0",47 "-methods", "test.mixed.JUnit3Test1.testB,test.mixed.JUnit4Test1.atest,test.mixed.TestNGTest1.tngCustomTest1"48 };49 TestListenerAdapter tla = new TestListenerAdapter();50 TestNG.privateMain(argv, tla);51 Assert.assertEquals(tla.getPassedTests().size(), 3);52 Assert.assertEquals(tla.getFailedTests().size(), 0);53 }54}...

Full Screen

Full Screen

Source:FailedInvocationCountTest.java Github

copy

Full Screen

...14 TestListenerAdapter tla = new TestListenerAdapter();15 testng.addListener(tla);16 testng.run();17 Assert.assertEquals(tla.getPassedTests().size(), passed);18 Assert.assertEquals(tla.getFailedTests().size(), failed);19 Assert.assertEquals(tla.getSkippedTests().size(), skipped);20 }21 @Test22 public void verifyGloballyShouldStop() {23 runTest(true, 4, 1, 5);24 }25 @Test26 public void verifyGloballyShouldNotStop() {27 runTest(false, 4, 6, 0);28 }29 @Test30 public void verifyAttributeShouldStop() {31 TestNG testng = new TestNG();32 testng.setVerbose(0);33 testng.setTestClasses(new Class[] { FailedInvocationCount2.class });34 TestListenerAdapter tla = new TestListenerAdapter();35 testng.addListener(tla);36 testng.run();37 Assert.assertEquals(tla.getPassedTests().size(), 8);38 Assert.assertEquals(tla.getFailedTests().size(), 7);39 Assert.assertEquals(tla.getSkippedTests().size(), 5);40 }41}...

Full Screen

Full Screen

Source:TestNGTestExecutor.java Github

copy

Full Screen

...25 }26 27 public int getRunCount() {28 return testListenerAdapter.getPassedTests().size() + 29 testListenerAdapter.getFailedTests().size() + 30 testListenerAdapter.getSkippedTests().size();31 }32 33 public int getFailureCount() {34 return testListenerAdapter.getFailedTests().size();35 }36 37 public int getIgnoreCount() {38 return testListenerAdapter.getSkippedTests().size();39 }40 41}...

Full Screen

Full Screen

getFailedTests

Using AI Code Generation

copy

Full Screen

1import org.testng.TestListenerAdapter;2import org.testng.TestNG;3import org.testng.xml.XmlSuite;4import java.util.ArrayList;5import java.util.List;6public class TestNGRunner {7 public static void main(String[] args) {8 TestListenerAdapter tla = new TestListenerAdapter();9 TestNG testng = new TestNG();10 testng.setTestClasses(new Class[] { TestClass1.class, TestClass2.class });11 testng.addListener(tla);12 testng.run();13 List<XmlSuite> failedTests = tla.getFailedTests();14 System.out.println(failedTests);15 }16}17import org.testng.TestListenerAdapter;18import org.testng.TestNG;19import org.testng.xml.XmlSuite;20import java.util.ArrayList;21import java.util.List;22public class TestNGRunner {23 public static void main(String[] args) {24 TestListenerAdapter tla = new TestListenerAdapter();25 TestNG testng = new TestNG();26 testng.setTestClasses(new Class[] { TestClass1.class, TestClass2.class });27 testng.addListener(tla);28 testng.run();29 List<XmlSuite> passedTests = tla.getPassedTests();30 System.out.println(passedTests);31 }32}33import org.testng.TestListenerAdapter;34import org.testng.TestNG;35import org.testng.xml.XmlSuite;36import java.util.ArrayList;37import java.util.List;38public class TestNGRunner {39 public static void main(String[] args) {40 TestListenerAdapter tla = new TestListenerAdapter();41 TestNG testng = new TestNG();42 testng.setTestClasses(new Class[] { TestClass1.class, TestClass2.class });43 testng.addListener(tla);44 testng.run();45 List<XmlSuite> skippedTests = tla.getSkippedTests();46 System.out.println(skippedTests);47 }48}49import org.testng.TestListenerAdapter;50import org.testng.TestNG;51import org.testng.xml.XmlSuite;52import java.util.ArrayList;53import java.util.List;54public class TestNGRunner {55 public static void main(String[] args) {56 TestListenerAdapter tla = new TestListenerAdapter();

Full Screen

Full Screen

getFailedTests

Using AI Code Generation

copy

Full Screen

1import org.testng.TestListenerAdapter;2import org.testng.TestNG;3import org.testng.xml.XmlSuite;4import java.util.List;5import java.util.ArrayList;6import java.util.Iterator;7import java.util.Arrays;8import java.util.Collections;9import java.util.Comparator;10import java.util.Map;11import java.util.HashMap;12public class TestNGListener extends TestListenerAdapter {13 Map<ITestResult, String> failedTests = new HashMap<ITestResult, String>();14 public Map<ITestResult, String> getFailedTests() {15 return failedTests;16 }17 public void onTestFailure(ITestResult tr) {18 failedTests.put(tr, tr.getThrowable().getMessage());19 }20}21public class RunTest {22 public static void main(String[] args) {23 TestNG runner = new TestNG();24 List<String> suitefiles = new ArrayList<String>();25 suitefiles.add("testng.xml");26 runner.setTestSuites(suitefiles);27 TestNGListener testListener = new TestNGListener();28 runner.addListener(testListener);29 runner.run();30 Map<ITestResult, String> failedTests = testListener.getFailedTests();31 Iterator<ITestResult> keys = failedTests.keySet().iterator();32 while (keys.hasNext()) {33 ITestResult key = keys.next();34 String value = failedTests.get(key);35 System.out.println("Test Name: " + key.getName());36 System.out.println("Failure Message: " + value);37 }38 }39}

Full Screen

Full Screen

getFailedTests

Using AI Code Generation

copy

Full Screen

1import org.testng.TestListenerAdapter;2import org.testng.ITestResult;3import org.testng.TestNG;4import java.util.List;5import java.util.ArrayList;6public class GetFailedTests {7 public static void main(String[] args) {8 TestNG testng = new TestNG();9 testng.setTestClasses(new Class[] { TestClass.class });10 TestListenerAdapter tla = new TestListenerAdapter();11 testng.addListener(tla);12 testng.run();13 List<ITestResult> failedTests = tla.getFailedTests();14 List<String> failedTestNames = new ArrayList<String>();15 for (ITestResult failedTest : failedTests) {16 failedTestNames.add(failedTest.getTestName());17 }18 System.out.println("Failed test names: " + failedTestNames);19 }20}

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