Best Testng code snippet using org.testng.TestListenerAdapter.getConfigurationFailures
Source:ListenerChainTest.java
...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 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
...
Source:ArtifactCollectorTest.java
...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}
...
Source:ExecutionFlowControllerTest.java
...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 }124
...
Source:TestRunnerTest.java
...84 @Test(expectedExceptions = Exception.class)85 public void testReportFailuresInvalid() throws Exception {86 new Expectations() {{87 tla.getFailedTests(); result = Collections.EMPTY_LIST;88 tla.getConfigurationFailures(); result = Collections.EMPTY_LIST;89 }};90 invoke(TestRunner.class, REPORT_FAILURES, tla);91 }92 @Test(expectedExceptions = Exception.class)93 public void testReportFailuresTestFailures() throws Exception {94 final String msg = "msg";95 new Expectations(tested) {{96 tla.getFailedTests(); result = new ArrayList<ITestResult>() {{ add(testResult); }};97 invoke(tested.getClass(), BUILD_ERROR_MESSAGE,98 new Class<?>[]{List.class}, (List<ITestResult>) any); result = msg;99 tla.getConfigurationFailures(); result = Collections.EMPTY_LIST;100 }};101 invoke(TestRunner.class, REPORT_FAILURES, tla);102 new Verifications() {{103 builder.append("Failed Tests:\n");104 builder.append(msg);105 }};106 }107 @Test(expectedExceptions = Exception.class)108 public void testReportFailuresConfigFailures() throws Exception {109 final String msg = "msg";110 new Expectations(tested) {{111 tla.getFailedTests(); result = Collections.EMPTY_LIST;112 tla.getConfigurationFailures(); result = new ArrayList<ITestResult>() {{ add(testResult); }};113 invoke(tested.getClass(), BUILD_ERROR_MESSAGE,114 new Class<?>[]{List.class}, (List<ITestResult>) any); result = msg;115 }};116 invoke(TestRunner.class, REPORT_FAILURES, tla);117 new Verifications() {{118 builder.append("Configuration Failures:\n");119 builder.append(msg);120 }};121 }122 @Test123 public void testBuildErrorMessageNoFailures() throws Exception {124 final String result = invoke(TestRunner.class, BUILD_ERROR_MESSAGE, Collections.EMPTY_LIST);125 assertThat(result).isEmpty();126 }...
Source:StaticFireBoosterTest.java
...74 @Override75 public void onFinish(final ITestContext testContext) {76 super.onFinish(testContext);77 FAILED.addAndGet(this.getFailedTests().size());78 FAILED.addAndGet(this.getConfigurationFailures().size());79 SKIPPED.addAndGet(this.getSkippedTests().size());80 PASSED.addAndGet(this.getPassedTests().size());81 }82 }83 public static class ParallelValidatingTestListener extends TestListenerAdapter {84 @Override85 public void onFinish(final ITestContext testContext) {86 super.onFinish(testContext);87 PARALLEL_FAILED.addAndGet(this.getFailedTests().size());88 PARALLEL_FAILED.addAndGet(this.getConfigurationFailures().size());89 PARALLEL_SKIPPED.addAndGet(this.getSkippedTests().size());90 PARALLEL_PASSED.addAndGet(this.getPassedTests().size());91 }92 }93}...
Source:TimeoutWithNoExecutorTest.java
...20 TestListenerAdapter listener = new TestListenerAdapter();21 testNG.addListener(listener);22 testNG.run();23 Assert.assertTrue(listener.getFailedTests().isEmpty());24 Assert.assertTrue(listener.getConfigurationFailures().isEmpty());25 }26}...
Source:IssueTest.java
...16 TestListenerAdapter listener = new TestListenerAdapter();17 tng.addListener(listener);18 tng.run();19 assertThat(listener.getFailedTests()).isEmpty();20 assertThat(listener.getConfigurationFailures()).isEmpty();21 }22}...
Source:RunSuite.java
...14 testng.setTestSuites(testFieldList);15 testng.addListener(tla);16 testng.setSuiteThreadPoolSize(2);17 testng.run();18 System.out.println("ConfigurationFailures: "+tla.getConfigurationFailures());19 System.out.println("getFailedTests()" + tla.getFailedTests());20 }21}...
getConfigurationFailures
Using AI Code Generation
1import org.testng.TestListenerAdapter;2import org.testng.TestNG;3import org.testng.xml.XmlSuite;4public class TestListenerAdapterDemo {5 public static void main(String[] args) {6 TestListenerAdapter tla = new TestListenerAdapter();7 TestNG testng = new TestNG();8 testng.addListener(tla);9 testng.setTestClasses(new Class[] { TestClass.class });10 testng.run();11 System.out.println("Test failures: " + tla.getFailedTests());12 System.out.println("Test skipped: " + tla.getSkippedTests());13 System.out.println("Test passed: " + tla.getPassedTests());14 }15}16package com.example;17import org.testng.annotations.Test;18public class TestClass {19 public void testMethod1() {20 System.out.println("Test method one");21 }22 public void testMethod2() {23 System.out.println("Test method two");24 }25}
getConfigurationFailures
Using AI Code Generation
1import org.testng.TestListenerAdapter;2import org.testng.TestNG;3public class TestNGGetConfigurationFailures {4 public static void main(String[] args) {5 TestNG testng = new TestNG();6 testng.setTestClasses(new Class[] { TestClassSample.class });7 TestListenerAdapter tla = new TestListenerAdapter();8 testng.addListener(tla);9 testng.run();10 System.out.println(tla.getConfigurationFailures());11 }12}13import org.testng.annotations.Test;14public class TestClassSample {15 public void testMethod() {16 System.out.println("testMethod");17 }18 public void testMethod2() {19 System.out.println("testMethod2");20 }21 public void testMethod3() {22 System.out.println("testMethod3");23 }24}
getConfigurationFailures
Using AI Code Generation
1package com.test;2import org.testng.ITestResult;3import org.testng.TestListenerAdapter;4public class TestNGTestListener extends TestListenerAdapter {5 public void onTestFailure(ITestResult tr) {6 System.out.println("Test failed");7 }8 public void onTestSkipped(ITestResult tr) {9 System.out.println("Test skipped");10 }11 public void onTestSuccess(ITestResult tr) {12 System.out.println("Test passed");13 }14}15package com.test;16import org.testng.annotations.Listeners;17import org.testng.annotations.Test;18@Listeners(com.test.TestNGTestListener.class)19public class TestNGTest {20 public void testMethod1() {21 System.out.println("Running Test -> testMethod1");22 }23}24package com.test;25import org.testng.TestNG;26import org.testng.annotations.Test;27public class TestNGRunner {28 public void runTestNG() {29 TestNG testng = new TestNG();30 testng.setTestClasses(new Class[] { TestNGTest.class });31 testng.run();32 }33}34package com.test;35import org.testng.annotations.Test;36public class TestNGTest2 {37 public void testMethod2() {38 System.out.println("Running Test -> testMethod2");39 }40}41package com.test;42import org.testng.TestNG;43import org.testng.annotations.Test;44public class TestNGRunner2 {45 public void runTestNG() {46 TestNG testng = new TestNG();47 testng.setTestClasses(new Class[] { TestNGTest2.class });48 testng.run();49 }50}51package com.test;52import org.testng.TestNG;53import org.testng.annotations.Test;54public class TestNGRunner3 {55 public void runTestNG() {56 TestNG testng = new TestNG();57 testng.setTestClasses(new Class[] { TestNGTest2.class, TestNGTest
getConfigurationFailures
Using AI Code Generation
1package com.example;2import org.testng.TestListenerAdapter;3import org.testng.TestNG;4import org.testng.xml.XmlSuite;5import org.testng.xml.XmlTest;6import java.util.ArrayList;7import java.util.List;8public class TestNGTest {9 public static void main(String[] args) {10 TestNG testNG = new TestNG();11 testNG.setVerbose(1);12 XmlSuite suite = new XmlSuite();13 suite.setName("TestNG Test Suite");14 XmlTest test = new XmlTest(suite);15 test.setName("TestNG Test");16 List<XmlSuite> suites = new ArrayList<>();17 suites.add(suite);18 testNG.setXmlSuites(suites);19 TestListenerAdapter tla = new TestListenerAdapter();20 testNG.addListener(tla);21 testNG.run();22 System.out.println(tla.getConfigurationFailures());23 }24}25[org.testng.internal.thread.ThreadTimeoutException: Method com.example.TestNGTest.main() didn't finish within the time-out 60000]
getConfigurationFailures
Using AI Code Generation
1import org.testng.TestListenerAdapter;2import org.testng.TestNG;3import org.testng.annotations.Test;4public class TestListenerAdapterDemo {5 public void test() {6 TestListenerAdapter tla = new TestListenerAdapter();7 TestNG testng = new TestNG();8 testng.setTestClasses(new Class[] { TestClassSample.class });9 testng.addListener(tla);10 testng.run();11 System.out.println("Failed configuration methods:");12 for (Object failedMethod : tla.getFailedConfigurationResults().getAllMethods()) {13 System.out.println(failedMethod.toString());14 }15 }16}17public class TestClassSample {18 public void testMethod() {19 System.out.println("Test method");20 }21 public void testMethod2() {22 System.out.println("Test method 2");23 }24 public void testMethod3() {25 System.out.println("Test method 3");26 }27 public void testMethod4() {28 System.out.println("Test method 4");29 }30 public void testMethod5() {31 System.out.println("Test method 5");32 }33 public void testMethod6() {34 System.out.println("Test method 6");35 }36}37import org.testng.TestListenerAdapter;38import org.testng.TestNG;39import org.testng.annotations.Test;40public class TestListenerAdapterDemo {41 public void test() {42 TestListenerAdapter tla = new TestListenerAdapter();43 TestNG testng = new TestNG();44 testng.setTestClasses(new Class[] { Test
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!!