Best Testng code snippet using org.testng.TestListenerAdapter.getConfigurationSkips
Source:ListenerChainTest.java
...33 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");34 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");35 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");36 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");37 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");38 39 assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));40 assertTrue(chainedListener.configSuccess.contains("afterSuccess"));41 assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));42 assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));43 44 assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));45 assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));46 assertTrue(chainedListener.testMethodBefore.contains("happyPath"));47 assertTrue(chainedListener.testMethodAfter.contains("happyPath"));48 assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));49 assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));50 51 assertTrue(chainedListener.testStarted.contains("happyPath"));52 assertTrue(chainedListener.testSuccess.contains("happyPath"));53 54 assertTrue(chainedListener.beforeClass.contains("ListenerChainTestCases"));55 assertTrue(chainedListener.afterClass.contains("ListenerChainTestCases"));56 57 assertTrue(chainedListener.testsBegun.contains("Command line test"));58 assertTrue(chainedListener.testsEnded.contains("Command line test"));59 60 assertTrue(chainedListener.suiteBegun.contains("Command line suite"));61 assertTrue(chainedListener.suiteEnded.contains("Command line suite"));62 63 Set<String> expectTests = new HashSet<>(Arrays.asList("method: testSkipped",64 "method: happyPath", "method: beforeSuccess", "method: beforeSkipped",65 "method: skipBeforeFailed", "method: skipBeforeSkipped",66 "method: testAfterSkipped", "method: productTest", "method: failAndPass",67 "method: afterSuccess", "method: afterFailure",68 "class: ListenerChainTestCases", "method: testAfterFailed",69 "method: beforeFailure", "method: afterSkipped", "method: testFailed",70 "method: testAttachedListeners"));71 Set<String> expectConfigs = new HashSet<>(Arrays.asList("method: afterSuccess",72 "method: afterFailure", "method: beforeSuccess", "method: beforeFailure",73 "method: beforeSkipped", "method: afterSkipped"));74 75 assertEquals(chainedListener.xformTest, expectTests);76 assertEquals(chainedListener.xformConfig, expectConfigs);77 assertTrue(chainedListener.xformProvider.contains("method: dataProvider"));78 assertTrue(chainedListener.xformFactory.contains("method: createInstances"));79 assertTrue(chainedListener.xformListeners.contains("class: ListenerChainTestCases"));80 81 assertTrue(chainedListener.interceptor.contains("Command line test"));82 }83 84 @Test85 public void verifyTestFailed() {86 87 ListenerChain lc = new ListenerChain();88 TestListenerAdapter tla = new TestListenerAdapter();89 90 TestNG testNG = new TestNG();91 testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});92 testNG.addListener((ITestNGListener) lc);93 testNG.addListener((ITestNGListener) tla);94 testNG.setGroups("testFailed");95 testNG.run();96 97 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();98 99 assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");100 assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");101 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");102 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");103 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");104 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");105 106 assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));107 assertTrue(chainedListener.configSuccess.contains("afterSuccess"));108 assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));109 assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));110 111 assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));112 assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));113 assertTrue(chainedListener.testMethodBefore.contains("testFailed"));114 assertTrue(chainedListener.testMethodAfter.contains("testFailed"));115 assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));116 assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));117 118 assertTrue(chainedListener.testStarted.contains("testFailed"));119 assertTrue(chainedListener.testFailure.contains("testFailed"));120 121 }122 123 @Test124 public void verifyTestSkipped() {125 126 ListenerChain lc = new ListenerChain();127 TestListenerAdapter tla = new TestListenerAdapter();128 129 TestNG testNG = new TestNG();130 testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});131 testNG.addListener((ITestNGListener) lc);132 testNG.addListener((ITestNGListener) tla);133 testNG.setGroups("testSkipped");134 testNG.run();135 136 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();137 138 assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");139 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");140 assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");141 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");142 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");143 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");144 145 assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));146 assertTrue(chainedListener.configSuccess.contains("afterSuccess"));147 assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));148 assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));149 150 assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));151 assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));152 assertTrue(chainedListener.testMethodBefore.contains("testSkipped"));153 assertTrue(chainedListener.testMethodAfter.contains("testSkipped"));154 assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));155 assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));156 157 assertTrue(chainedListener.testStarted.contains("testSkipped"));158 assertTrue(chainedListener.testSkipped.contains("testSkipped"));159 160 }161 162 @Test163 public void verifyFailAndPass() {164 165 ListenerChain lc = new ListenerChain();166 TestListenerAdapter tla = new TestListenerAdapter();167 168 TestNG testNG = new TestNG();169 testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});170 testNG.addListener((ITestNGListener) lc);171 testNG.addListener((ITestNGListener) tla);172 testNG.setGroups("failAndPass");173 testNG.run();174 175 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();176 177 assertEquals(tla.getPassedTests().size(), 3, "Incorrect passed test count");178 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");179 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");180 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 1, "Incorrect curve-graded success count");181 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");182 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");183 184 assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));185 assertTrue(chainedListener.configSuccess.contains("afterSuccess"));186 assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));187 assertTrue(chainedListener.beforeConfig.contains("afterSuccess"));188 189 assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));190 assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));191 assertTrue(chainedListener.testMethodBefore.contains("failAndPass"));192 assertTrue(chainedListener.testMethodAfter.contains("failAndPass"));193 assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess"));194 assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess"));195 196 assertTrue(chainedListener.testStarted.contains("failAndPass"));197 assertTrue(chainedListener.testCurved.contains("failAndPass"));198 199 }200 201 @Test202 public void verifyBeforeFailed() {203 204 ListenerChain lc = new ListenerChain();205 TestListenerAdapter tla = new TestListenerAdapter();206 207 TestNG testNG = new TestNG();208 testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});209 testNG.addListener((ITestNGListener) lc);210 testNG.addListener((ITestNGListener) tla);211 testNG.setGroups("beforeFailed");212 testNG.run();213 214 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();215 216 assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");217 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");218 assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");219 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");220 assertEquals(tla.getConfigurationFailures().size(), 1, "Incorrect configuration method failure count");221 assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration method skip count");222 223 assertTrue(chainedListener.configFailure.contains("beforeFailure"));224 assertTrue(chainedListener.configSkipped.contains("afterSuccess"));225 assertTrue(chainedListener.beforeConfig.contains("beforeFailure"));226 227 assertTrue(chainedListener.beforeMethodBefore.contains("beforeFailure"));228 assertTrue(chainedListener.beforeMethodAfter.contains("beforeFailure"));229 assertTrue(chainedListener.testMethodBefore.contains("skipBeforeFailed"));230 assertTrue(chainedListener.testMethodAfter.contains("skipBeforeFailed"));231 232 assertTrue(chainedListener.testStarted.contains("skipBeforeFailed"));233 assertTrue(chainedListener.testSkipped.contains("skipBeforeFailed"));234 235 }236 237 @Test238 public void verifyBeforeSkipped() {239 240 ListenerChain lc = new ListenerChain();241 TestListenerAdapter tla = new TestListenerAdapter();242 243 TestNG testNG = new TestNG();244 testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});245 testNG.addListener((ITestNGListener) lc);246 testNG.addListener((ITestNGListener) tla);247 testNG.setGroups("beforeSkipped");248 testNG.run();249 250 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();251 252 assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");253 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");254 assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");255 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");256 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");257 assertEquals(tla.getConfigurationSkips().size(), 2, "Incorrect configuration method skip count");258 259 assertTrue(chainedListener.configSkipped.contains("beforeSkipped"));260 assertTrue(chainedListener.configSkipped.contains("afterSuccess"));261 assertTrue(chainedListener.beforeConfig.contains("beforeSkipped"));262 263 assertTrue(chainedListener.beforeMethodBefore.contains("beforeSkipped"));264 assertTrue(chainedListener.beforeMethodAfter.contains("beforeSkipped"));265 assertTrue(chainedListener.testMethodBefore.contains("skipBeforeSkipped"));266 assertTrue(chainedListener.testMethodAfter.contains("skipBeforeSkipped"));267 268 assertTrue(chainedListener.testStarted.contains("skipBeforeSkipped"));269 assertTrue(chainedListener.testSkipped.contains("skipBeforeSkipped"));270 271 }272 273 @Test274 public void verifyAfterFailed() {275 276 ListenerChain lc = new ListenerChain();277 TestListenerAdapter tla = new TestListenerAdapter();278 279 TestNG testNG = new TestNG();280 testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});281 testNG.addListener((ITestNGListener) lc);282 testNG.addListener((ITestNGListener) tla);283 testNG.setGroups("afterFailed");284 testNG.run();285 286 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();287 288 assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");289 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");290 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");291 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");292 assertEquals(tla.getConfigurationFailures().size(), 1, "Incorrect configuration method failure count");293 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");294 295 assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));296 assertTrue(chainedListener.configFailure.contains("afterFailure"));297 assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));298 assertTrue(chainedListener.beforeConfig.contains("afterFailure"));299 300 assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));301 assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));302 assertTrue(chainedListener.testMethodBefore.contains("testAfterFailed"));303 assertTrue(chainedListener.testMethodAfter.contains("testAfterFailed"));304 assertTrue(chainedListener.afterMethodBefore.contains("afterFailure"));305 assertTrue(chainedListener.afterMethodAfter.contains("afterFailure"));306 307 assertTrue(chainedListener.testStarted.contains("testAfterFailed"));308 assertTrue(chainedListener.testSuccess.contains("testAfterFailed"));309 310 }311 312 @Test313 public void verifyAfterSkipped() {314 315 ListenerChain lc = new ListenerChain();316 TestListenerAdapter tla = new TestListenerAdapter();317 318 TestNG testNG = new TestNG();319 testNG.setTestClasses(new Class[]{ListenerChainTestCases.class});320 testNG.addListener((ITestNGListener) lc);321 testNG.addListener((ITestNGListener) tla);322 testNG.setGroups("afterSkipped");323 testNG.run();324 325 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();326 327 assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");328 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");329 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");330 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");331 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");332 assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration method skip count");333 334 assertTrue(chainedListener.configSuccess.contains("beforeSuccess"));335 assertTrue(chainedListener.configSkipped.contains("afterSkipped"));336 assertTrue(chainedListener.beforeConfig.contains("beforeSuccess"));337 assertTrue(chainedListener.beforeConfig.contains("afterSkipped"));338 339 assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess"));340 assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess"));341 assertTrue(chainedListener.testMethodBefore.contains("testAfterSkipped"));342 assertTrue(chainedListener.testMethodAfter.contains("testAfterSkipped"));343 assertTrue(chainedListener.afterMethodBefore.contains("afterSkipped"));344 assertTrue(chainedListener.afterMethodAfter.contains("afterSkipped"));345 346 assertTrue(chainedListener.testStarted.contains("testAfterSkipped"));347 assertTrue(chainedListener.testSuccess.contains("testAfterSkipped"));348 349 }350351 @Test352 public void verifyConstructorFactory(){353 ListenerChain lc = new ListenerChain();354 TestListenerAdapter tla = new TestListenerAdapter();355356 TestNG testNG = new TestNG();357 testNG.setTestClasses(new Class[]{ConstructorFactory.class});358 testNG.addListener((ITestNGListener) lc);359 testNG.addListener((ITestNGListener) tla);360 testNG.run();361362 ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get();363 364 assertEquals(tla.getPassedTests().size(), 3, "Incorrect passed test count");365 assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");366 assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");367 assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");368 assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");369 assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");370 371 assertTrue(chainedListener.testMethodBefore.contains("fakeTest"));372 assertTrue(chainedListener.testMethodAfter.contains("fakeTest"));373 374 assertTrue(chainedListener.testStarted.contains("fakeTest"));375 assertTrue(chainedListener.testSuccess.contains("fakeTest"));376 377 assertTrue(chainedListener.beforeClass.contains("ConstructorFactory"));378 assertTrue(chainedListener.afterClass.contains("ConstructorFactory"));379 380 assertTrue(chainedListener.testsBegun.contains("Command line test"));381 assertTrue(chainedListener.testsEnded.contains("Command line test"));382 383 assertTrue(chainedListener.suiteBegun.contains("Command line suite"));
...
Source:ArtifactCollectorTest.java
...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}
...
Source:FailurePolicyTest.java
...79 verify(tla, 2, 0, 2);80 }81 private void verify( TestListenerAdapter tla, int configurationFailures, int configurationSkips, int skippedTests ) {82 assertEquals(tla.getConfigurationFailures().size(), configurationFailures, "wrong number of configuration failures");83 assertEquals(tla.getConfigurationSkips().size(), configurationSkips, "wrong number of configuration skips");84 assertEquals(tla.getSkippedTests().size(), skippedTests, "wrong number of skipped tests");85 }86}...
Source:SkippedExceptionTest.java
...20 test.addListener(listener);21 test.setVerbose(0);22 test.setTestClasses(new Class[] {ConfigurationSkippedExceptionTest.class});23 test.run();24 List<ITestResult> confSkips= listener.getConfigurationSkips();25 List<ITestResult> testSkips= listener.getSkippedTests();26 Assert.assertEquals(testSkips.size(), 1);27 Assert.assertEquals(testSkips.get(0).getMethod().getMethodName(), "dummyTest");2829 Assert.assertEquals(confSkips.size(), 1);30 Assert.assertEquals(confSkips.get(0).getMethod().getMethodName(), "configurationLevelSkipException");31 }323334 @Test35 public void skippedExceptionInTestMethods() {36 TestListenerAdapter listener= new TestListenerAdapter();37 TestNG test= new TestNG(false);38 test.addListener(listener);
...
Source:IssueTest.java
...9 public void ensureConfigurationsCanBeRetriedViaCallBacks() {10 TestNG testng = create(TestClassSample.class);11 TestListenerAdapter listener = new TestListenerAdapter();12 testng.run();13 assertThat(listener.getConfigurationSkips()).isEmpty();14 assertThat(listener.getConfigurationFailures()).isEmpty();15 assertThat(testng.getStatus()).isEqualTo(0);16 }17}...
getConfigurationSkips
Using AI Code Generation
1package com.test;2import org.testng.annotations.Test;3import org.testng.Assert;4import org.testng.ITestResult;5import org.testng.annotations.AfterMethod;6import org.testng.annotations.BeforeMethod;7import org.testng.annotations.Test;8import org.testng.annotations.BeforeTest;9import org.testng.annotations.AfterTest;10import org.testng.annotations.BeforeClass;11import org.testng.annotations.AfterClass;12import org.testng.annotations.BeforeSuite;13import org.testng.annotations.AfterSuite;14import org.testng.annotations.DataProvider;15import org.testng.annotations.Listeners;16import org.testng.SkipException;17@Listeners(com.test.TestListener.class)18public class TestNGListenerDemo {19 public void testMethod1() {20 System.out.println("Running Test -> testMethod1");21 Assert.assertTrue(true);22 }23 public void testMethod2() {24 System.out.println("Running Test -> testMethod2");25 Assert.assertTrue(false);26 }27 public void testMethod3() {28 System.out.println("Running Test -> testMethod3");29 throw new SkipException("Skipping - This is not ready for testing ");30 }31}32package com.test;33import org.testng.ITestContext;34import org.testng.ITestListener;35import org.testng.ITestResult;36public class TestListener implements ITestListener {37 public void onFinish(ITestContext Result) {38 System.out.println("The name of the testcase finished is :"+Result.getName());39 }40 public void onStart(ITestContext Result) {41 System.out.println("The name of the testcase started is :"+Result.getName());42 }43 public void onTestFailedButWithinSuccessPercentage(ITestResult Result) {44 System.out.println("The name of the testcase failed is :"+Result.getName());45 }46 public void onTestFailure(ITestResult Result) {47 System.out.println("The name of the testcase failed is :"+Result.getName());48 }49 public void onTestSkipped(ITestResult Result) {50 System.out.println("The name of the testcase skipped is :"+Result.getName());51 }52 public void onTestStart(ITestResult Result) {53 System.out.println(Result.getName()+" test case started");54 }55 public void onTestSuccess(ITestResult Result) {56 System.out.println("The name of the testcase passed is :"+Result.getName());57 }58}
getConfigurationSkips
Using AI Code Generation
1package org.testng.examples;2import org.testng.TestListenerAdapter;3import org.testng.TestNG;4import org.testng.annotations.Test;5public class TestListenerAdapterExample {6 public void testListenerAdapterExample() {7 TestListenerAdapter tla = new TestListenerAdapter();8 TestNG testng = new TestNG();9 testng.setTestClasses(new Class[] { TestClassSample1.class, TestClassSample2.class });10 testng.addListener(tla);11 testng.run();12 boolean skipConfig = tla.getConfigurationSkips();13 if(skipConfig) {14 System.out.println("Skipping the configuration methods of the test classes.");15 } else {16 System.out.println("Executing the configuration methods of the test classes.");17 }18 }19}20package org.testng.examples;21import org.testng.TestListenerAdapter;22import org.testng.TestNG;23import org.testng.annotations.Test;24public class TestListenerAdapterExample {25 public void testListenerAdapterExample() {26 TestListenerAdapter tla = new TestListenerAdapter();27 TestNG testng = new TestNG();28 testng.setTestClasses(new Class[] { TestClassSample1.class, TestClassSample2.class });29 testng.addListener(tla);30 testng.run();31 boolean skipConfig = tla.getConfigurationSkips();32 if(skipConfig) {33 System.out.println("Skipping the configuration methods of the test classes.");34 } else {35 System.out.println("Executing the configuration methods of the test classes.");36 }37 }38 public boolean getConfigurationSkips() {39 return true;40 }41}
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!!