How to use TestRunner class of org.testng package

Best Testng code snippet using org.testng.TestRunner

Source:VerifyTests.java Github

copy

Full Screen

...45 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)46 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)47 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)48 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)49 at org.testng.TestRunner.privateRun(TestRunner.java:767)50 at org.testng.TestRunner.run(TestRunner.java:617)51 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)52 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)53 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)54 at org.testng.SuiteRunner.run(SuiteRunner.java:240)55 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)56 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)57 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)58 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)59 at org.testng.TestNG.run(TestNG.java:1057)60 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)61 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)62 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)63 Failure 2 of 364 org.muthu.VerificationError: test4 doesn't matches expected [test4] but found [test#]65 at org.testng.Assert.fail(Assert.java:94)66 at org.testng.Assert.failNotEquals(Assert.java:494)67 at org.testng.Assert.assertEquals(Assert.java:123)68 at org.testng.Assert.assertEquals(Assert.java:176)69 at org.muthu.Verify.verifyEquals(Verify.java:90)70 at org.muthu.TestVerify.test01(TestVerify.java:17)71 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)72 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)73 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)74 at java.lang.reflect.Method.invoke(Unknown Source)75 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)76 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)77 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)78 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)79 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)80 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)81 at org.testng.TestRunner.privateRun(TestRunner.java:767)82 at org.testng.TestRunner.run(TestRunner.java:617)83 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)84 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)85 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)86 at org.testng.SuiteRunner.run(SuiteRunner.java:240)87 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)88 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)89 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)90 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)91 at org.testng.TestNG.run(TestNG.java:1057)92 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)93 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)94 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)95 Failure 3 of 396 java.lang.AssertionError: test7 doesn't matches expected [test7] but found [test$]97 at org.testng.Assert.fail(Assert.java:94)98 at org.testng.Assert.failNotEquals(Assert.java:494)99 at org.testng.Assert.assertEquals(Assert.java:123)100 at org.testng.Assert.assertEquals(Assert.java:176)101 at org.muthu.TestVerify.test01(TestVerify.java:20)102 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)103 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)104 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)105 at java.lang.reflect.Method.invoke(Unknown Source)106 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)107 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)108 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)109 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)110 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)111 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)112 at org.testng.TestRunner.privateRun(TestRunner.java:767)113 at org.testng.TestRunner.run(TestRunner.java:617)114 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)115 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)116 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)117 at org.testng.SuiteRunner.run(SuiteRunner.java:240)118 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)119 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)120 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)121 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)122 at org.testng.TestNG.run(TestNG.java:1057)123 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)124 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)125 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)126 ===============================================127 Default test128 Tests run: 1, Failures: 1, Skips: 0129 ===============================================*/130 131 }132 133 @Test134 public void verifyNotEqualsTest(){135 136 /* verifyNotEquals */137 Verify.verifyNotEquals("test!", "test1", "test1 matches"); // pass138 Verify.verifyNotEquals("test2", "test2", "test2 matches"); // fail (continue)139 Verify.verifyNotEquals("test!", "test3", "test3 matches"); // pass140 Verify.verifyNotEquals("test4", "test4", "test4 matches"); // fail (continue)141 Verify.verifyNotEquals("test!", "test5", "test5 matches"); // pass142 Verify.verifyNotEquals("test!", "test6", "test6 matches"); // pass143 Assert.assertNotEquals("test7", "test7", "test7 matches"); // fail (exit) 144 Assert.assertNotEquals("test!", "test8", "test8 matches"); // not run!145 Verify.verifyNotEquals("test!", "test9", "test9 matches"); // not run!146 147 // Output148 149/* FAILED: verifyNotEqualsTest150 java.lang.Throwable: Multiple failures (3)151 (1)org.muthu.VerificationError:test2 matches152 (2)org.muthu.VerificationError:test4 matches153 (3)java.lang.AssertionError:test7 matches154 Failure 1 of 3155 org.muthu.VerificationError: test2 matches156 at org.testng.Assert.fail(Assert.java:94)157 at org.testng.Assert.assertNotEquals(Assert.java:854)158 at org.muthu.Verify.verifyNotEquals(Verify.java:434)159 at org.muthu.TestVerify.verifyNotEqualsTest(TestVerify.java:143)160 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)161 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)162 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)163 at java.lang.reflect.Method.invoke(Unknown Source)164 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)165 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)166 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)167 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)168 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)169 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)170 at org.testng.TestRunner.privateRun(TestRunner.java:767)171 at org.testng.TestRunner.run(TestRunner.java:617)172 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)173 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)174 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)175 at org.testng.SuiteRunner.run(SuiteRunner.java:240)176 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)177 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)178 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)179 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)180 at org.testng.TestNG.run(TestNG.java:1057)181 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)182 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)183 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)184 Failure 2 of 3185 org.muthu.VerificationError: test4 matches186 at org.testng.Assert.fail(Assert.java:94)187 at org.testng.Assert.assertNotEquals(Assert.java:854)188 at org.muthu.Verify.verifyNotEquals(Verify.java:434)189 at org.muthu.TestVerify.verifyNotEqualsTest(TestVerify.java:145)190 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)191 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)192 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)193 at java.lang.reflect.Method.invoke(Unknown Source)194 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)195 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)196 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)197 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)198 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)199 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)200 at org.testng.TestRunner.privateRun(TestRunner.java:767)201 at org.testng.TestRunner.run(TestRunner.java:617)202 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)203 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)204 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)205 at org.testng.SuiteRunner.run(SuiteRunner.java:240)206 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)207 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)208 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)209 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)210 at org.testng.TestNG.run(TestNG.java:1057)211 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)212 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)213 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)214 Failure 3 of 3215 java.lang.AssertionError: test7 matches216 at org.testng.Assert.fail(Assert.java:94)217 at org.testng.Assert.assertNotEquals(Assert.java:854)218 at org.muthu.TestVerify.verifyNotEqualsTest(TestVerify.java:148)219 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)220 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)221 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)222 at java.lang.reflect.Method.invoke(Unknown Source)223 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)224 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)225 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)226 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)227 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)228 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)229 at org.testng.TestRunner.privateRun(TestRunner.java:767)230 at org.testng.TestRunner.run(TestRunner.java:617)231 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)232 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)233 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)234 at org.testng.SuiteRunner.run(SuiteRunner.java:240)235 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)236 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)237 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)238 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)239 at org.testng.TestNG.run(TestNG.java:1057)240 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)241 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)242 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)243 ===============================================244 Default test245 Tests run: 1, Failures: 1, Skips: 0246 ===============================================247*/248 }249 @Test250 public void verifyTrueTest(){251 252 /* verifyTrue */253 Verify.verifyTrue(true, "test1 condition is false"); // pass254 Verify.verifyTrue(false, "test2 condition is false"); // fail (continue)255 Verify.verifyTrue(true, "test3 condition is false"); // pass256 Verify.verifyTrue(false, "test4 condition is false"); // fail (continue)257 Verify.verifyTrue(true, "test5 condition is false"); // pass258 Verify.verifyTrue(true, "test6 condition is false"); // pass259 Assert.assertTrue(false, "test7 condition is false"); // fail (exit) 260 Assert.assertTrue(true, "test8 condition is false"); // not run!261 Verify.verifyTrue(true, "test9 condition is false"); // not run!262 263 // Output264 265/* Failure 1 of 3266 org.muthu.VerificationError: test2 condition is false expected [true] but found [false]267 at org.testng.Assert.fail(Assert.java:94)268 at org.testng.Assert.failNotEquals(Assert.java:494)269 at org.testng.Assert.assertTrue(Assert.java:42)270 at org.muthu.Verify.verifyTrue(Verify.java:18)271 at org.muthu.TestVerify.verifyTrueTest(TestVerify.java:265)272 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)273 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)274 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)275 at java.lang.reflect.Method.invoke(Unknown Source)276 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)277 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)278 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)279 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)280 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)281 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)282 at org.testng.TestRunner.privateRun(TestRunner.java:767)283 at org.testng.TestRunner.run(TestRunner.java:617)284 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)285 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)286 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)287 at org.testng.SuiteRunner.run(SuiteRunner.java:240)288 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)289 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)290 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)291 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)292 at org.testng.TestNG.run(TestNG.java:1057)293 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)294 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)295 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)296 Failure 2 of 3297 org.muthu.VerificationError: test4 condition is false expected [true] but found [false]298 at org.testng.Assert.fail(Assert.java:94)299 at org.testng.Assert.failNotEquals(Assert.java:494)300 at org.testng.Assert.assertTrue(Assert.java:42)301 at org.muthu.Verify.verifyTrue(Verify.java:18)302 at org.muthu.TestVerify.verifyTrueTest(TestVerify.java:267)303 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)304 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)305 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)306 at java.lang.reflect.Method.invoke(Unknown Source)307 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)308 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)309 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)310 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)311 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)312 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)313 at org.testng.TestRunner.privateRun(TestRunner.java:767)314 at org.testng.TestRunner.run(TestRunner.java:617)315 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)316 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)317 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)318 at org.testng.SuiteRunner.run(SuiteRunner.java:240)319 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)320 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)321 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)322 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)323 at org.testng.TestNG.run(TestNG.java:1057)324 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)325 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)326 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)327 Failure 3 of 3328 java.lang.AssertionError: test7 condition is false expected [true] but found [false]329 at org.testng.Assert.fail(Assert.java:94)330 at org.testng.Assert.failNotEquals(Assert.java:494)331 at org.testng.Assert.assertTrue(Assert.java:42)332 at org.muthu.TestVerify.verifyTrueTest(TestVerify.java:270)333 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)334 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)335 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)336 at java.lang.reflect.Method.invoke(Unknown Source)337 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)338 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)339 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)340 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)341 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)342 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)343 at org.testng.TestRunner.privateRun(TestRunner.java:767)344 at org.testng.TestRunner.run(TestRunner.java:617)345 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)346 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)347 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)348 at org.testng.SuiteRunner.run(SuiteRunner.java:240)349 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)350 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)351 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)352 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)353 at org.testng.TestNG.run(TestNG.java:1057)354 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)355 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)356 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)357 ===============================================358 Default test359 Tests run: 1, Failures: 1, Skips: 0360 ===============================================361*/362 }363 364 @Test365 public void exceptionTest(){366 367 String str = null;368 369 /* verifyEquals */370 Verify.verifyEquals("test1", "test1", "test1 doesn't match"); // pass371 Verify.verifyEquals("test!", "test2", "test2 doesn't match"); // fail (continue)372 Verify.verifyEquals("test3", "test3", "test3 doesn't match"); // pass373 374 /*375 * Test run will not continue if there is any exception/error (except Assertion error) during verification 376 */377 Verify.verifyEquals("test#", str.substring(0), "test4 doesn't match"); // fail (exit) 378 379 380 Verify.verifyEquals("test5", "test5", "test5 doesn't match"); // not run!381 Verify.verifyEquals("test6", "test6", "test6 doesn't match"); // not run!382 Assert.assertEquals("test$", "test7", "test7 doesn't match"); // not run! 383 Assert.assertEquals("test8", "test8", "test8 doesn't match"); // not run!384 Verify.verifyEquals("test9", "test9", "test9 doesn't match"); // not run!385 // Output386 387/* FAILED: exceptionTest388 java.lang.Throwable: Multiple failures (2)389 (1)org.muthu.VerificationError:test2 doesn't match expected [test2] but found [test!]390 (2)java.lang.NullPointerException:null391 Failure 1 of 2392 org.muthu.VerificationError: test2 doesn't match expected [test2] but found [test!]393 at org.testng.Assert.fail(Assert.java:94)394 at org.testng.Assert.failNotEquals(Assert.java:494)395 at org.testng.Assert.assertEquals(Assert.java:123)396 at org.testng.Assert.assertEquals(Assert.java:176)397 at org.muthu.Verify.verifyEquals(Verify.java:90)398 at org.muthu.TestVerify.exceptionTest(TestVerify.java:386)399 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)400 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)401 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)402 at java.lang.reflect.Method.invoke(Unknown Source)403 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)404 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)405 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)406 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)407 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)408 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)409 at org.testng.TestRunner.privateRun(TestRunner.java:767)410 at org.testng.TestRunner.run(TestRunner.java:617)411 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)412 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)413 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)414 at org.testng.SuiteRunner.run(SuiteRunner.java:240)415 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)416 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)417 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)418 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)419 at org.testng.TestNG.run(TestNG.java:1057)420 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)421 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)422 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)423 Failure 2 of 2424 java.lang.NullPointerException425 at org.muthu.TestVerify.exceptionTest(TestVerify.java:392)426 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)427 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)428 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)429 at java.lang.reflect.Method.invoke(Unknown Source)430 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)431 at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)432 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)433 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)434 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)435 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)436 at org.testng.TestRunner.privateRun(TestRunner.java:767)437 at org.testng.TestRunner.run(TestRunner.java:617)438 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)439 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)440 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)441 at org.testng.SuiteRunner.run(SuiteRunner.java:240)442 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)443 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)444 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)445 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)446 at org.testng.TestNG.run(TestNG.java:1057)447 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)448 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)449 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)450 ===============================================451 Default test...

Full Screen

Full Screen

Source:SuiteRunner.java Github

copy

Full Screen

...34public class SuiteRunner implements ISuite, IInvokedMethodListener {35 private static final String DEFAULT_OUTPUT_DIR = "test-output";36 private Map<String, ISuiteResult> suiteResults =37 Collections.synchronizedMap(Maps.newLinkedHashMap());38 private List<TestRunner> testRunners = Lists.newArrayList();39 private Map<Class<? extends ISuiteListener>, ISuiteListener> listeners = Maps.newHashMap();40 private TestListenerAdapter textReporter = new TestListenerAdapter();41 private String outputDir;42 private XmlSuite xmlSuite;43 private Injector parentInjector;44 private List<ITestListener> testListeners = Lists.newArrayList();45 private final Map<Class<? extends IClassListener>, IClassListener> classListeners =46 Maps.newHashMap();47 private final Map<Class<? extends IDataProviderListener>, IDataProviderListener>48 dataProviderListeners = Maps.newHashMap();49 private ITestRunnerFactory tmpRunnerFactory;50 private boolean useDefaultListeners = true;51 // The remote host where this suite was run, or null if run locally52 private String remoteHost;53 // The configuration54 private IConfiguration configuration;55 private ITestObjectFactory objectFactory;56 private Boolean skipFailedInvocationCounts = Boolean.FALSE;57 private List<IReporter> reporters = Lists.newArrayList();58 private Map<Class<? extends IInvokedMethodListener>, IInvokedMethodListener>59 invokedMethodListeners;60 /** The list of all the methods invoked during this run */61 private final Collection<IInvokedMethod> invokedMethods = new ConcurrentLinkedQueue<>();62 private List<ITestNGMethod> allTestMethods = Lists.newArrayList();63 private SuiteRunState suiteState = new SuiteRunState();64 private IAttributes attributes = new Attributes();65 private final Set<IExecutionVisualiser> visualisers = Sets.newHashSet();66 public SuiteRunner(67 IConfiguration configuration,68 XmlSuite suite,69 String outputDir,70 ITestRunnerFactory runnerFactory,71 Comparator<ITestNGMethod> comparator) {72 this(configuration, suite, outputDir, runnerFactory, false, comparator);73 }74 public SuiteRunner(75 IConfiguration configuration,76 XmlSuite suite,77 String outputDir,78 ITestRunnerFactory runnerFactory,79 boolean useDefaultListeners,80 Comparator<ITestNGMethod> comparator) {81 this(82 configuration,83 suite,84 outputDir,85 runnerFactory,86 useDefaultListeners,87 new ArrayList<>() /* method interceptor */,88 null /* invoked method listeners */,89 null /* test listeners */,90 null /* class listeners */,91 Collections.emptyMap(),92 comparator);93 }94 protected SuiteRunner(95 IConfiguration configuration,96 XmlSuite suite,97 String outputDir,98 ITestRunnerFactory runnerFactory,99 boolean useDefaultListeners,100 List<IMethodInterceptor> methodInterceptors,101 Collection<IInvokedMethodListener> invokedMethodListeners,102 Collection<ITestListener> testListeners,103 Collection<IClassListener> classListeners,104 Map<Class<? extends IDataProviderListener>, IDataProviderListener> dataProviderListeners,105 Comparator<ITestNGMethod> comparator) {106 init(107 configuration,108 suite,109 outputDir,110 runnerFactory,111 useDefaultListeners,112 methodInterceptors,113 invokedMethodListeners,114 testListeners,115 classListeners,116 dataProviderListeners,117 comparator);118 }119 private void init(120 IConfiguration configuration,121 XmlSuite suite,122 String outputDir,123 ITestRunnerFactory runnerFactory,124 boolean useDefaultListeners,125 List<IMethodInterceptor> methodInterceptors,126 Collection<IInvokedMethodListener> invokedMethodListener,127 Collection<ITestListener> testListeners,128 Collection<IClassListener> classListeners,129 Map<Class<? extends IDataProviderListener>, IDataProviderListener> dataProviderListeners,130 Comparator<ITestNGMethod> comparator) {131 this.configuration = configuration;132 xmlSuite = suite;133 this.useDefaultListeners = useDefaultListeners;134 tmpRunnerFactory = runnerFactory;135 List<IMethodInterceptor> localMethodInterceptors =136 methodInterceptors != null ? methodInterceptors : Lists.newArrayList();137 setOutputDir(outputDir);138 objectFactory = this.configuration.getObjectFactory();139 if (objectFactory == null) {140 objectFactory = suite.getObjectFactory();141 }142 // Add our own IInvokedMethodListener143 invokedMethodListeners = Maps.newHashMap();144 if (invokedMethodListener != null) {145 for (IInvokedMethodListener listener : invokedMethodListener) {146 invokedMethodListeners.put(listener.getClass(), listener);147 }148 }149 invokedMethodListeners.put(getClass(), this);150 skipFailedInvocationCounts = suite.skipFailedInvocationCounts();151 if (null != testListeners) {152 this.testListeners.addAll(testListeners);153 }154 if (null != classListeners) {155 for (IClassListener classListener : classListeners) {156 this.classListeners.put(classListener.getClass(), classListener);157 }158 }159 if (null != dataProviderListeners) {160 this.dataProviderListeners.putAll(dataProviderListeners);161 }162 if (comparator == null) {163 throw new IllegalArgumentException("comparator must not be null");164 }165 ITestRunnerFactory2 iTestRunnerFactory = buildRunnerFactory(comparator);166 // Order the <test> tags based on their order of appearance in testng.xml167 List<XmlTest> xmlTests = xmlSuite.getTests();168 xmlTests.sort(Comparator.comparingInt(XmlTest::getIndex));169 for (XmlTest test : xmlTests) {170 TestRunner tr =171 iTestRunnerFactory.newTestRunner(172 this,173 test,174 invokedMethodListeners.values(),175 Lists.newArrayList(this.classListeners.values()),176 this.dataProviderListeners);177 //178 // Install the method interceptor, if any was passed179 //180 for (IMethodInterceptor methodInterceptor : localMethodInterceptors) {181 tr.addMethodInterceptor(methodInterceptor);182 }183 // Reuse the same text reporter so we can accumulate all the results184 // (this is used to display the final suite report at the end)185 tr.addListener(textReporter);186 testRunners.add(tr);187 // Add the methods found in this test to our global count188 allTestMethods.addAll(Arrays.asList(tr.getAllTestMethods()));189 }190 }191 @Override192 public XmlSuite getXmlSuite() {193 return xmlSuite;194 }195 @Override196 public String getName() {197 return xmlSuite.getName();198 }199 public void setObjectFactory(ITestObjectFactory objectFactory) {200 this.objectFactory = objectFactory;201 }202 public void setReportResults(boolean reportResults) {203 useDefaultListeners = reportResults;204 }205 private void invokeListeners(boolean start) {206 for (ISuiteListener sl : listeners.values()) {207 if (start) {208 sl.onStart(this);209 } else {210 sl.onFinish(this);211 }212 }213 }214 private void setOutputDir(String outputdir) {215 if (isStringBlank(outputdir) && useDefaultListeners) {216 outputdir = DEFAULT_OUTPUT_DIR;217 }218 outputDir = (null != outputdir) ? new File(outputdir).getAbsolutePath() : null;219 }220 private ITestRunnerFactory2 buildRunnerFactory(Comparator<ITestNGMethod> comparator) {221 ITestRunnerFactory2 factory;222 if (null == tmpRunnerFactory) {223 factory =224 new DefaultTestRunnerFactory(225 configuration,226 testListeners.toArray(new ITestListener[0]),227 useDefaultListeners,228 skipFailedInvocationCounts,229 comparator);230 } else {231 factory =232 new ProxyTestRunnerFactory(testListeners.toArray(new ITestListener[0]), tmpRunnerFactory);233 }234 return factory;235 }236 @Override237 public String getParallel() {238 return xmlSuite.getParallel().toString();239 }240 @Override241 public String getParentModule() {242 return xmlSuite.getParentModule();243 }244 @Override245 public String getGuiceStage() {246 return xmlSuite.getGuiceStage();247 }248 @Override249 public Injector getParentInjector() {250 return parentInjector;251 }252 @Override253 public void setParentInjector(Injector injector) {254 parentInjector = injector;255 }256 @Override257 public void run() {258 invokeListeners(true /* start */);259 try {260 privateRun();261 } finally {262 invokeListeners(false /* stop */);263 }264 }265 private void privateRun() {266 // Map for unicity, Linked for guaranteed order267 Map<Method, ITestNGMethod> beforeSuiteMethods = new LinkedHashMap<>();268 Map<Method, ITestNGMethod> afterSuiteMethods = new LinkedHashMap<>();269 IInvoker invoker = null;270 // Get the invoker and find all the suite level methods271 for (TestRunner tr : testRunners) {272 // TODO: Code smell. Invoker should belong to SuiteRunner, not TestRunner273 // -- cbeust274 invoker = tr.getInvoker();275 for (ITestNGMethod m : tr.getBeforeSuiteMethods()) {276 beforeSuiteMethods.put(m.getConstructorOrMethod().getMethod(), m);277 }278 for (ITestNGMethod m : tr.getAfterSuiteMethods()) {279 afterSuiteMethods.put(m.getConstructorOrMethod().getMethod(), m);280 }281 }282 //283 // Invoke beforeSuite methods (the invoker can be null284 // if the suite we are currently running only contains285 // a <file-suite> tag and no real tests)286 //287 if (invoker != null) {288 if (!beforeSuiteMethods.values().isEmpty()) {289 invoker.invokeConfigurations(290 null,291 beforeSuiteMethods.values().toArray(new ITestNGMethod[0]),292 xmlSuite,293 xmlSuite.getParameters(),294 null, /* no parameter values */295 null /* instance */);296 }297 Utils.log("SuiteRunner", 3, "Created " + testRunners.size() + " TestRunners");298 //299 // Run all the test runners300 //301 boolean testsInParallel = XmlSuite.ParallelMode.TESTS.equals(xmlSuite.getParallel());302 if (!testsInParallel) {303 runSequentially();304 } else {305 runInParallelTestMode();306 }307 //308 // Invoke afterSuite methods309 //310 if (!afterSuiteMethods.values().isEmpty()) {311 invoker.invokeConfigurations(312 null,313 afterSuiteMethods.values().toArray(new ITestNGMethod[0]),314 xmlSuite,315 xmlSuite.getAllParameters(),316 null, /* no parameter values */317 null /* instance */);318 }319 }320 }321 private void addVisualiser(IExecutionVisualiser visualiser) {322 visualisers.add(visualiser);323 }324 private void addReporter(IReporter listener) {325 reporters.add(listener);326 }327 void addConfigurationListener(IConfigurationListener listener) {328 configuration.addConfigurationListener(listener);329 }330 public List<IReporter> getReporters() {331 return reporters;332 }333 private void runSequentially() {334 for (TestRunner tr : testRunners) {335 runTest(tr);336 }337 }338 private void runTest(TestRunner tr) {339 visualisers.forEach(tr::addListener);340 tr.run();341 ISuiteResult sr = new SuiteResult(xmlSuite, tr);342 suiteResults.put(tr.getName(), sr);343 }344 /**345 * Implement <suite parallel="tests">. Since this kind of parallelism happens at the suite level,346 * we need a special code path to execute it. All the other parallelism strategies are implemented347 * at the test level in TestRunner#createParallelWorkers (but since this method deals with just348 * one <test> tag, it can't implement <suite parallel="tests">, which is why we're doing it here).349 */350 private void runInParallelTestMode() {351 List<Runnable> tasks = Lists.newArrayList(testRunners.size());352 for (TestRunner tr : testRunners) {353 tasks.add(new SuiteWorker(tr));354 }355 ThreadUtil.execute(356 "tests",357 tasks,358 xmlSuite.getThreadCount(),359 xmlSuite.getTimeOut(XmlTest.DEFAULT_TIMEOUT_MS),360 false);361 }362 private class SuiteWorker implements Runnable {363 private TestRunner testRunner;364 public SuiteWorker(TestRunner tr) {365 testRunner = tr;366 }367 @Override368 public void run() {369 Utils.log(370 "[SuiteWorker]",371 4,372 "Running XML Test '" + testRunner.getTest().getName() + "' in Parallel");373 runTest(testRunner);374 }375 }376 /** Registers ISuiteListeners interested in reporting the result of the current suite. */377 protected void addListener(ISuiteListener reporter) {378 if (!listeners.containsKey(reporter.getClass())) {379 listeners.put(reporter.getClass(), reporter);380 }381 }382 @Override383 public void addListener(ITestNGListener listener) {384 if (listener instanceof IInvokedMethodListener) {385 IInvokedMethodListener invokedMethodListener = (IInvokedMethodListener) listener;386 invokedMethodListeners.put(invokedMethodListener.getClass(), invokedMethodListener);387 }388 if (listener instanceof ISuiteListener) {389 addListener((ISuiteListener) listener);390 }391 if (listener instanceof IExecutionVisualiser) {392 addVisualiser((IExecutionVisualiser) listener);393 }394 if (listener instanceof IReporter) {395 addReporter((IReporter) listener);396 }397 if (listener instanceof IConfigurationListener) {398 addConfigurationListener((IConfigurationListener) listener);399 }400 if (listener instanceof IClassListener) {401 IClassListener classListener = (IClassListener) listener;402 if (!classListeners.containsKey(classListener.getClass())) {403 classListeners.put(classListener.getClass(), classListener);404 }405 }406 }407 @Override408 public String getOutputDirectory() {409 return outputDir + File.separatorChar + getName();410 }411 @Override412 public Map<String, ISuiteResult> getResults() {413 return suiteResults;414 }415 /**416 * FIXME: should be removed?417 *418 * @see org.testng.ISuite#getParameter(java.lang.String)419 */420 @Override421 public String getParameter(String parameterName) {422 return xmlSuite.getParameter(parameterName);423 }424 /** @see org.testng.ISuite#getMethodsByGroups() */425 @Override426 public Map<String, Collection<ITestNGMethod>> getMethodsByGroups() {427 Map<String, Collection<ITestNGMethod>> result = Maps.newHashMap();428 for (TestRunner tr : testRunners) {429 ITestNGMethod[] methods = tr.getAllTestMethods();430 for (ITestNGMethod m : methods) {431 String[] groups = m.getGroups();432 for (String groupName : groups) {433 Collection<ITestNGMethod> testMethods =434 result.computeIfAbsent(groupName, k -> Lists.newArrayList());435 testMethods.add(m);436 }437 }438 }439 return result;440 }441 /** @see org.testng.ISuite#getExcludedMethods() */442 @Override443 public Collection<ITestNGMethod> getExcludedMethods() {444 return getIncludedOrExcludedMethods(false /* included */);445 }446 private Collection<ITestNGMethod> getIncludedOrExcludedMethods(boolean included) {447 List<ITestNGMethod> result = Lists.newArrayList();448 for (TestRunner tr : testRunners) {449 Collection<ITestNGMethod> methods =450 included ? tr.getInvokedMethods() : tr.getExcludedMethods();451 result.addAll(methods);452 }453 return result;454 }455 @Override456 public IObjectFactory getObjectFactory() {457 return objectFactory instanceof IObjectFactory ? (IObjectFactory) objectFactory : null;458 }459 @Override460 public IObjectFactory2 getObjectFactory2() {461 return objectFactory instanceof IObjectFactory2 ? (IObjectFactory2) objectFactory : null;462 }463 /**464 * Returns the annotation finder for the given annotation type.465 *466 * @return the annotation finder for the given annotation type.467 */468 @Override469 public IAnnotationFinder getAnnotationFinder() {470 return configuration.getAnnotationFinder();471 }472 public static void ppp(String s) {473 System.out.println("[SuiteRunner] " + s);474 }475 /** The default implementation of {@link ITestRunnerFactory}. */476 private static class DefaultTestRunnerFactory implements ITestRunnerFactory2 {477 private ITestListener[] failureGenerators;478 private boolean useDefaultListeners;479 private boolean skipFailedInvocationCounts;480 private IConfiguration configuration;481 private final Comparator<ITestNGMethod> comparator;482 public DefaultTestRunnerFactory(483 IConfiguration configuration,484 ITestListener[] failureListeners,485 boolean useDefaultListeners,486 boolean skipFailedInvocationCounts,487 Comparator<ITestNGMethod> comparator) {488 this.configuration = configuration;489 failureGenerators = failureListeners;490 this.useDefaultListeners = useDefaultListeners;491 this.skipFailedInvocationCounts = skipFailedInvocationCounts;492 this.comparator = comparator;493 }494 @Override495 public TestRunner newTestRunner(496 ISuite suite,497 XmlTest test,498 Collection<IInvokedMethodListener> listeners,499 List<IClassListener> classListeners) {500 return newTestRunner(suite, test, listeners, classListeners, Collections.emptyMap());501 }502 @Override503 public TestRunner newTestRunner(504 ISuite suite,505 XmlTest test,506 Collection<IInvokedMethodListener> listeners,507 List<IClassListener> classListeners,508 Map<Class<? extends IDataProviderListener>, IDataProviderListener> dataProviderListeners) {509 boolean skip = skipFailedInvocationCounts;510 if (!skip) {511 skip = test.skipFailedInvocationCounts();512 }513 TestRunner testRunner =514 new TestRunner(515 configuration,516 suite,517 test,518 suite.getOutputDirectory(),519 suite.getAnnotationFinder(),520 skip,521 listeners,522 classListeners,523 comparator,524 dataProviderListeners);525 if (useDefaultListeners) {526 testRunner.addListener(new TestHTMLReporter());527 testRunner.addListener(new JUnitXMLReporter());528 // TODO: Moved these here because maven2 has output reporters running529 // already, the output from these causes directories to be created with530 // files. This is not the desired behaviour of running tests in maven2.531 // Don't know what to do about this though, are people relying on these532 // to be added even with defaultListeners set to false?533 testRunner.addListener(new TextReporter(testRunner.getName(), TestRunner.getVerbose()));534 }535 for (ITestListener itl : failureGenerators) {536 testRunner.addTestListener(itl);537 }538 for (IConfigurationListener cl : configuration.getConfigurationListeners()) {539 testRunner.addConfigurationListener(cl);540 }541 return testRunner;542 }543 }544 private static class ProxyTestRunnerFactory implements ITestRunnerFactory2 {545 private ITestListener[] failureGenerators;546 private ITestRunnerFactory target;547 public ProxyTestRunnerFactory(ITestListener[] failureListeners, ITestRunnerFactory target) {548 failureGenerators = failureListeners;549 this.target = target;550 }551 @Override552 public TestRunner newTestRunner(553 ISuite suite,554 XmlTest test,555 Collection<IInvokedMethodListener> listeners,556 List<IClassListener> classListeners) {557 return newTestRunner(suite, test, listeners, classListeners, Collections.emptyMap());558 }559 @Override560 public TestRunner newTestRunner(561 ISuite suite,562 XmlTest test,563 Collection<IInvokedMethodListener> listeners,564 List<IClassListener> classListeners,565 Map<Class<? extends IDataProviderListener>, IDataProviderListener> dataProviderListeners) {566 TestRunner testRunner;567 if (target instanceof ITestRunnerFactory2) {568 testRunner =569 ((ITestRunnerFactory2) target)570 .newTestRunner(suite, test, listeners, classListeners, dataProviderListeners);571 } else {572 testRunner = target.newTestRunner(suite, test, listeners, classListeners);573 }574 testRunner.addListener(new TextReporter(testRunner.getName(), TestRunner.getVerbose()));575 for (ITestListener itl : failureGenerators) {576 testRunner.addListener(itl);577 }578 return testRunner;579 }580 }581 public void setHost(String host) {582 remoteHost = host;583 }584 @Override585 public String getHost() {586 return remoteHost;587 }588 /** @see org.testng.ISuite#getSuiteState() */...

Full Screen

Full Screen

Source:RemoteTestNG.java Github

copy

Full Screen

...9import org.testng.IClassListener;10import org.testng.IInvokedMethodListener;11import org.testng.ISuite;12import org.testng.ISuiteListener;13import org.testng.ITestRunnerFactory;14import org.testng.TestNG;15import org.testng.TestNGException;16import org.testng.TestRunner;17import org.testng.collections.Lists;18import org.testng.remote.strprotocol.GenericMessage;19import org.testng.remote.strprotocol.IMessageSender;20import org.testng.remote.strprotocol.MessageHelper;21import org.testng.remote.strprotocol.MessageHub;22import org.testng.remote.strprotocol.RemoteTestListener;23import org.testng.remote.strprotocol.SerializedMessageSender;24import org.testng.remote.strprotocol.StringMessageSender;25import org.testng.remote.strprotocol.SuiteMessage;26import org.testng.reporters.JUnitXMLReporter;27import org.testng.reporters.TestHTMLReporter;28import org.testng.xml.XmlSuite;29import org.testng.xml.XmlTest;3031import java.util.Arrays;32import java.util.Collection;33import java.util.List;3435/**36 * Extension of TestNG registering a remote TestListener.37 *38 * @author Cedric Beust <cedric@beust.com>39 */40public class RemoteTestNG extends TestNG {41 private static final String LOCALHOST = "localhost";4243 // The following constants are referenced by the Eclipse plug-in, make sure you44 // modify the plug-in as well if you change any of them.45 public static final String DEBUG_PORT = "12345";46 public static final String DEBUG_SUITE_FILE = "testng-customsuite.xml";47 public static final String DEBUG_SUITE_DIRECTORY = System.getProperty("java.io.tmpdir");48 public static final String PROPERTY_DEBUG = "testng.eclipse.debug";49 public static final String PROPERTY_VERBOSE = "testng.eclipse.verbose";50 // End of Eclipse constants.5152 private ITestRunnerFactory m_customTestRunnerFactory;53 private String m_host;5455 /** Port used for the string protocol */56 private Integer m_port = null;5758 /** Port used for the serialized protocol */59 private static Integer m_serPort = null;6061 private static boolean m_debug;6263 private static boolean m_dontExit;6465 private static boolean m_ack;6667 public void setHost(String host) {68 m_host = defaultIfStringEmpty(host, LOCALHOST);69 }7071 private void calculateAllSuites(List<XmlSuite> suites, List<XmlSuite> outSuites) {72 for (XmlSuite s : suites) {73 outSuites.add(s);74// calculateAllSuites(s.getChildSuites(), outSuites);75 }76 }7778 @Override79 public void run() {80 IMessageSender sender = m_serPort != null81 ? new SerializedMessageSender(m_host, m_serPort, m_ack)82 : new StringMessageSender(m_host, m_port);83 final MessageHub msh = new MessageHub(sender);84 msh.setDebug(isDebug());85 try {86 msh.connect();87 // We couldn't do this until now in debug mode since the .xml file didn't exist yet.88 // Now that we have connected with the Eclipse client, we know that it created the .xml89 // file so we can proceed with the initialization90 initializeSuitesAndJarFile();9192 List<XmlSuite> suites = Lists.newArrayList();93 calculateAllSuites(m_suites, suites);94// System.out.println("Suites: " + m_suites.get(0).getChildSuites().size()95// + " and:" + suites.get(0).getChildSuites().size());96 if(suites.size() > 0) {9798 int testCount= 0;99100 for (XmlSuite suite : suites) {101 testCount += suite.getTests().size();102 }103104 GenericMessage gm= new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT);105 gm.setSuiteCount(suites.size());106 gm.setTestCount(testCount);107 msh.sendMessage(gm);108109 addListener(new RemoteSuiteListener(msh));110 setTestRunnerFactory(new DelegatingTestRunnerFactory(buildTestRunnerFactory(), msh));111112// System.out.println("RemoteTestNG starting");113 super.run();114 }115 else {116 System.err.println("No test suite found. Nothing to run");117 }118 }119 catch(Throwable cause) {120 cause.printStackTrace(System.err);121 }122 finally {123// System.out.println("RemoteTestNG finishing: " + (getEnd() - getStart()) + " ms");124 msh.shutDown();125 if (! m_debug && ! m_dontExit) {126 System.exit(0);127 }128 }129 }130131 /**132 * Override by the plugin if you need to configure differently the <code>TestRunner</code>133 * (usually this is needed if different listeners/reporters are needed).134 * <b>Note</b>: you don't need to worry about the wiring listener, because it is added135 * automatically.136 */137 protected ITestRunnerFactory buildTestRunnerFactory() {138 if(null == m_customTestRunnerFactory) {139 m_customTestRunnerFactory= new ITestRunnerFactory() {140 @Override141 public TestRunner newTestRunner(ISuite suite, XmlTest xmlTest,142 Collection<IInvokedMethodListener> listeners, List<IClassListener> classListeners) {143 TestRunner runner =144 new TestRunner(getConfiguration(), suite, xmlTest,145 false /*skipFailedInvocationCounts */,146 listeners, classListeners);147 if (m_useDefaultListeners) {148 runner.addListener(new TestHTMLReporter());149 runner.addListener(new JUnitXMLReporter());150 }151152 return runner;153 }154 };155 }156157 return m_customTestRunnerFactory;158 }159160 public static void main(String[] args) throws ParameterException {161 CommandLineArgs cla = new CommandLineArgs();162 RemoteArgs ra = new RemoteArgs();163 new JCommander(Arrays.asList(cla, ra), args);164 m_dontExit = ra.dontExit;165 if (cla.port != null && ra.serPort != null) {166 throw new TestNGException("Can only specify one of " + CommandLineArgs.PORT167 + " and " + RemoteArgs.PORT);168 }169 m_debug = cla.debug;170 m_ack = ra.ack;171 if (m_debug) {172// while (true) {173 initAndRun(args, cla, ra);174// }175 }176 else {177 initAndRun(args, cla, ra);178 }179 }180181 private static void initAndRun(String[] args, CommandLineArgs cla, RemoteArgs ra) {182 RemoteTestNG remoteTestNg = new RemoteTestNG();183 if (m_debug) {184 // In debug mode, override the port and the XML file to a fixed location185 cla.port = Integer.parseInt(DEBUG_PORT);186 ra.serPort = cla.port;187 cla.suiteFiles = Arrays.asList(new String[] {188 DEBUG_SUITE_DIRECTORY + DEBUG_SUITE_FILE189 });190 }191 remoteTestNg.configure(cla);192 remoteTestNg.setHost(cla.host);193 m_serPort = ra.serPort;194 remoteTestNg.m_port = cla.port;195 if (isVerbose()) {196 StringBuilder sb = new StringBuilder("Invoked with ");197 for (String s : args) {198 sb.append(s).append(" ");199 }200 p(sb.toString());201// remoteTestNg.setVerbose(1);202// } else {203// remoteTestNg.setVerbose(0);204 }205 validateCommandLineParameters(cla);206 remoteTestNg.run();207// if (m_debug) {208// // Run in a loop if in debug mode so it is possible to run several launches209// // without having to relauch RemoteTestNG.210// while (true) {211// remoteTestNg.run();212// remoteTestNg.configure(cla);213// }214// } else {215// remoteTestNg.run();216// }217 }218219 private static void p(String s) {220 if (isVerbose()) {221 System.out.println("[RemoteTestNG] " + s);222 }223 }224225 public static boolean isVerbose() {226 boolean result = System.getProperty(PROPERTY_VERBOSE) != null || isDebug();227 return result;228 }229230 public static boolean isDebug() {231 return m_debug || System.getProperty(PROPERTY_DEBUG) != null;232 }233234 private String getHost() {235 return m_host;236 }237238 private int getPort() {239 return m_port;240 }241242 /** A ISuiteListener wiring the results using the internal string-based protocol. */243 private static class RemoteSuiteListener implements ISuiteListener {244 private final MessageHub m_messageSender;245246 RemoteSuiteListener(MessageHub smsh) {247 m_messageSender= smsh;248 }249250 @Override251 public void onFinish(ISuite suite) {252 m_messageSender.sendMessage(new SuiteMessage(suite, false /*start*/));253 }254255 @Override256 public void onStart(ISuite suite) {257 m_messageSender.sendMessage(new SuiteMessage(suite, true /*start*/));258 }259 }260261 private static class DelegatingTestRunnerFactory implements ITestRunnerFactory {262 private final ITestRunnerFactory m_delegateFactory;263 private final MessageHub m_messageSender;264265 DelegatingTestRunnerFactory(ITestRunnerFactory trf, MessageHub smsh) {266 m_delegateFactory= trf;267 m_messageSender= smsh;268 }269270 @Override271 public TestRunner newTestRunner(ISuite suite, XmlTest test,272 Collection<IInvokedMethodListener> listeners, List<IClassListener> classListeners) {273 TestRunner tr = m_delegateFactory.newTestRunner(suite, test, listeners, classListeners);274 tr.addListener(new RemoteTestListener(suite, test, m_messageSender));275 return tr;276 }277 }278} ...

Full Screen

Full Screen

Source:NativeDependencyInjectionTestng.java Github

copy

Full Screen

...5import org.apache.commons.collections4.IterableUtils;6import org.testng.ITestClass;7import org.testng.ITestContext;8import org.testng.ITestResult;9import org.testng.TestRunner;10import org.testng.annotations.AfterClass;11import org.testng.annotations.AfterGroups;12import org.testng.annotations.AfterMethod;13import org.testng.annotations.AfterSuite;14import org.testng.annotations.AfterTest;15import org.testng.annotations.BeforeClass;16import org.testng.annotations.BeforeGroups;17import org.testng.annotations.BeforeMethod;18import org.testng.annotations.BeforeSuite;19import org.testng.annotations.BeforeTest;20import org.testng.annotations.DataProvider;21import org.testng.annotations.Test;22import org.testng.xml.XmlClass;23import org.testng.xml.XmlTest;24/**25 * <a href="http://testng.org/doc/documentation-main.html#native-dependency-injection">native-dependency-injection</a>: <br/>26 * <pre>27 * | Annotation | {@linkplain ITestContext} | {@linkplain XmlTest} | {@linkplain Method} | Object[] | {@linkplain ITestResult} |28 * |:-------------|:-------------|:--------|:-------|:---------|:------------|29 * | {@linkplain BeforeSuite} | Yes | | | | |30 * | {@linkplain BeforeTest} | Yes | Yes | | | |31 * | {@linkplain BeforeGroups} | Yes | Yes | | | |32 * | {@linkplain BeforeClass} | Yes | Yes | | | |33 * | {@linkplain BeforeMethod} | Yes | Yes | Yes | Yes | Yes |34 * | {@linkplain Test} | Yes | | | | |35 * | {@linkplain DataProvider} | Yes | | Yes | | |36 * | {@linkplain AfterMethod} | Yes | Yes | Yes | Yes | Yes |37 * | {@linkplain AfterClass} | Yes | Yes | | | |38 * | {@linkplain AfterGroups} | Yes | Yes | | | |39 * | {@linkplain AfterTest} | Yes | Yes | | | |40 * | {@linkplain AfterSuite} | Yes | | | | |41 * </pre>42 *43 * @author vergilyn44 * @since 2021-08-0245 *46 */47public class NativeDependencyInjectionTestng {48 @BeforeClass49 public void beforeClass(ITestContext testContext, XmlTest xmlTest){50 TestRunner testRunner = (TestRunner) testContext;51 // TODO 2021-08-02 区别?更建议使用哪种方式?52 Collection<ITestClass> testClasses = testRunner.getTestClasses();53 System.out.printf("beforeClass[TestRunner] >>>> test-class-name: %s \n",54 IterableUtils.get(testClasses, 0).getRealClass().getName());55 List<XmlClass> classes = xmlTest.getClasses();56 System.out.printf("beforeClass[XmlTest] >>>> test-class-name: %s \n",57 classes.get(0).getName());58 }59 @BeforeMethod // The annotated method will be run before each test method.60 public void BeforeMethod(ITestContext testContext, XmlTest xmlTest, Method method, Object[] objects, ITestResult testResult){61 System.out.printf("beforeMethod >>>> method-name: %s \n", method.getName());62 Test annotation = method.getAnnotation(Test.class);63 // 如果是`test02`会是""64 System.out.printf("beforeMethod >>>> test-name: %s \n", annotation.testName());65 }66 @Test(testName = "test-name-01")67 public void test01(){...

Full Screen

Full Screen

Source:TestRunnerFactory.java Github

copy

Full Screen

...27import org.testng.IClassListener;28import org.testng.IInvokedMethodListener;29import org.testng.ISuite;30import org.testng.ITestNGMethod;31import org.testng.ITestRunnerFactory;32import org.testng.TestRunner;33import org.testng.internal.IConfiguration;34import org.testng.internal.TestNGMethod;35import org.testng.xml.XmlTest;3637import com.qmetry.qaf.automation.step.client.TestNGScenario;3839/**40 * 41 * @author chirag.jayswal42 *43 */44public class TestRunnerFactory implements ITestRunnerFactory {45 46 private IConfiguration configuration;47 private ITestRunnerFactory testRunnerFactory;48 49 public TestRunnerFactory(IConfiguration configuration) {50 this.configuration = configuration;51 }52 public TestRunnerFactory(ITestRunnerFactory testRunnerFactory) {53 this.testRunnerFactory = testRunnerFactory;54 }5556 @Override57 public TestRunner newTestRunner(ISuite suite, XmlTest test, Collection<IInvokedMethodListener> listeners,58 List<IClassListener> classListeners) {59 TestRunner runner = null!=testRunnerFactory?testRunnerFactory.newTestRunner(suite, test, listeners, classListeners):60 new TestRunner(configuration, suite, test,61 false /*skipFailedInvocationCounts */,62 listeners,classListeners);;63 init(runner);64 return runner;65 }66 private void init(TestRunner runner){67 convert(runner.getAllTestMethods());68 convert(runner.getAfterSuiteMethods());69 convert(runner.getAfterTestConfigurationMethods());70 convert(runner.getBeforeSuiteMethods());71 convert(runner.getBeforeTestConfigurationMethods());72 }73 private void convert(ITestNGMethod[] m){74 for(int i=0;i<m.length;i++){75 if(m[i] instanceof TestNGMethod && !(m[i] instanceof TestNGScenario)){76 m[i]=new TestNGScenario((TestNGMethod) m[i]);77 }78 }79 }80 ...

Full Screen

Full Screen

Source:IJUnitTestRunner.java Github

copy

Full Screen

...56import org.testng.IInvokedMethodListener;7import org.testng.ITestNGMethod;8import org.testng.TestNGException;9import org.testng.TestRunner;10import org.testng.internal.ClassHelper;11import org.testng.internal.ITestResultNotifier;12import org.testng.internal.Utils;1314/**15 * An abstraction interface over JUnit test runners.16 *17 */18public interface IJUnitTestRunner {1920 String JUNIT_TESTRUNNER = "org.testng.junit.JUnitTestRunner";21 String JUNIT_4_TESTRUNNER = "org.testng.junit.JUnit4TestRunner";222324 void setInvokedMethodListeners(Collection<IInvokedMethodListener> listener);2526 void setTestResultNotifier(ITestResultNotifier notifier);2728 void run(Class junitTestClass, String... methods);2930 List<ITestNGMethod> getTestMethods();3132 static IJUnitTestRunner createTestRunner(TestRunner runner) {33 IJUnitTestRunner tr = null;34 try {35 // try to get runner for JUnit 4 first36 Class.forName("org.junit.Test");37 Class<?> clazz = ClassHelper.forName(JUNIT_4_TESTRUNNER);38 if (clazz != null) {39 tr = (IJUnitTestRunner) clazz.newInstance();40 tr.setTestResultNotifier(runner);41 }42 } catch (Throwable t) {43 Utils.log(IJUnitTestRunner.class.getSimpleName(), 2, "JUnit 4 was not found on the classpath");44 try {45 // fallback to JUnit 346 Class.forName("junit.framework.Test");47 Class<?> clazz = ClassHelper.forName(JUNIT_TESTRUNNER);48 if (clazz != null) {49 tr = (IJUnitTestRunner) clazz.newInstance();50 tr.setTestResultNotifier(runner);51 }52 } catch (Exception ex) {53 Utils.log(IJUnitTestRunner.class.getSimpleName(), 2, "JUnit 3 was not found on the classpath");54 // there's no JUnit on the classpath55 throw new TestNGException("Cannot create JUnit runner", ex);56 }57 }58 return tr;59 }60} ...

Full Screen

Full Screen

Source:TestngReport.java Github

copy

Full Screen

...3import java.util.List;4import org.testng.ISuite;5import org.testng.ISuiteResult;6import org.testng.SuiteRunner;7import org.testng.TestRunner;8import org.testng.reporters.XMLReporter;9import org.testng.xml.XmlSuite;10import org.testng.xml.XmlTest;11public class TestngReport12{13 public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException, SecurityException14 {15 //SuiteHTMLReporter reporter = new SuiteHTMLReporter();16 XMLReporter xmlreporter = new XMLReporter();17 18 List<XmlSuite> xmlSuites = new ArrayList<>();19 XmlSuite xs = new XmlSuite();20 List<XmlTest> tests = new ArrayList<>();21 XmlTest xt = new XmlTest();22 xt.setName("Test/gogo");23 tests.add(xt);24 xs.setTests(tests);25 List<ISuite> suites = new ArrayList<>();26 SuiteRunner sr = new SuiteRunner(null, xs, null);27 Class clazz = Class.forName("org.testng.SuiteResult");28 ISuiteResult sres = (ISuiteResult) clazz.newInstance();29 30 TestRunner tr = new TestRunner(null, sr, xt, false, null);31 clazz.getField("m_testContext");32 33 String outputDirectory = "c:/report";34 xmlreporter.generateReport(xmlSuites, suites, outputDirectory );35 }36}...

Full Screen

Full Screen

Source:91b95.java Github

copy

Full Screen

1diff --git a/src/main/org/testng/TestRunner.java b/src/main/org/testng/TestRunner.java2index f595d58..d23b72f 1006443--- a/src/main/org/testng/TestRunner.java4+++ b/src/main/org/testng/TestRunner.java5@@ -261,8 +261,7 @@6 m_testName,7 testMethodFinder,8 m_annotationFinder,9- m_runInfo,10- this);11+ m_runInfo);12 m_classMap.put(ic.getRealClass(), tc);13 }14 ...

Full Screen

Full Screen

TestRunner

Using AI Code Generation

copy

Full Screen

1import org.testng.TestRunner;2import org.testng.TestNG;3import java.io.File;4import java.io.FileInputStream;5import java.io.IOException;6import java.util.Properties;7import java.lang.String;8import java.util.ArrayList;9import java.util.List;10import java.util.Iterator;11import java.io.File;12import java.io.FileFilter;13import java.lang.String;14import java.util.List;15import java.util.ArrayList;16import java.util.Iterator;17import java.io.File;18import java.io.FileFilter;19import java.lang.String;20import java.util.List;21import java.util.ArrayList;22import java.util.Iterator;23import java.io.File;24import java.io.FileFilter;25import java.lang.String;26import java.util.List;27import java.util.ArrayList;28import java.util.Iterator;29import java.io.File;30import java.io.FileFilter;31import java.lang.String;

Full Screen

Full Screen

TestRunner

Using AI Code Generation

copy

Full Screen

1import org.testng.TestRunner;2import org.testng.TestNG;3import org.testng.xml.XmlSuite;4import org.testng.xml.XmlTest;5import org.testng.xml.XmlClass;6import org.testng.xml.XmlInclude;7import org.testng.xml.XmlPackage;8import org.testng.xml.XmlGroups;9import org.testng.xml.XmlGroup;10import org.testng.xml.XmlRun;11import org.testng.xml.XmlSuite.ParallelMode;12XmlSuite suite = new XmlSuite();13suite.setName("TestNG Suite");14XmlTest test = new XmlTest(suite);15test.setName("TestNG Test");16XmlClass testClass = new XmlClass("testClass");17testClass.setIncludedMethods(Arrays.asList(new XmlInclude("testMethod")));18XmlPackage testPackage = new XmlPackage("testPackage");19XmlRun testRun = new XmlRun();20testRun.onInclude("testMethod");21XmlGroup testGroup = new XmlGroup();22testGroup.setName("testGroup");23XmlGroups testGroups = new XmlGroups();24testGroups.setRun(testRun);25testGroups.setIncludedGroups(Arrays.asList(testGroup));26ParallelMode testParallelMode = ParallelMode.METHODS;27TestRunner testRunner = new TestRunner();28testRunner.setTest(test);29testRunner.setTestClasses(new XmlClass[]{testClass});30testRunner.setTestPackages(new XmlPackage[]{testPackage});31testRunner.setTestGroups(testGroups);32testRunner.setTestParallelMode(testParallelMode);33TestNG testNG = new TestNG();34testNG.setTestSuites(Arrays.asList("testSuite.xml"));35testNG.setXmlSuites(Arrays.asList(suite));36testNG.setTestClasses(new Class[]{testClass.getClass()});37testNG.setTestPackages(new String[]{testPackage.getName()});38testNG.setTestGroups(Arrays.asList(testGroup.getName()));39testNG.setTestListeners(new String[]{"testListener"});40testNG.setTestRunner(testRunner);41testNG.setParallel(testParallelMode.toString());42testNG.setThreadCount(10);43testNG.setSuiteThreadPoolSize(10);44testNG.setVerbose(10);

Full Screen

Full Screen

TestRunner

Using AI Code Generation

copy

Full Screen

1package com.test;2import java.util.ArrayList;3import java.util.List;4import org.testng.TestNG;5import org.testng.xml.XmlClass;6import org.testng.xml.XmlInclude;7import org.testng.xml.XmlPackage;8import org.testng.xml.XmlSuite;9import org.testng.xml.XmlTest;10public class TestRunner {11 public static void main(String[] args) {12 TestNG runner = new TestNG();13 XmlSuite suite = new XmlSuite();14 suite.setName("TestNG Suite");15 XmlTest test = new XmlTest(suite);16 test.setName("TestNG Test");17 test.setPreserveOrder("true");18 test.setParallel(XmlSuite.ParallelMode.METHODS);19 List<XmlClass> classes = new ArrayList<XmlClass>();20 test.setXmlClasses(classes);21 List<XmlPackage> packages = new ArrayList<XmlPackage>();22 XmlPackage xmlPackage = new XmlPackage("com.test");23 packages.add(xmlPackage);24 test.setXmlPackages(packages);25 List<XmlInclude> methodsToRun = new ArrayList<XmlInclude>();

Full Screen

Full Screen

TestRunner

Using AI Code Generation

copy

Full Screen

1package com.test;2import org.testng.TestNG;3public class TestRunner {4public static void main(String[] args) {5TestNG runner=new TestNG();6List<String> suitefiles=new ArrayList<String>();7suitefiles.add("C:\\Users\\Sai\\Desktop\\TestNG\\testng.xml");8runner.setTestSuites(suitefiles);9runner.run();10}11}

Full Screen

Full Screen

TestRunner

Using AI Code Generation

copy

Full Screen

1import org.testng.TestRunner;2import org.testng.TestNG;3import org.testng.xml.XmlSuite;4import java.util.ArrayList;5import java.util.List;6import java.util.Map;7import java.util.HashMap;8import java.util.Iterator;9import java.util.Set;10import java.util.HashSet;11import java.util.Arrays;12import org.testng.TestRunner;13import org.testng.TestNG;14import org.testng.xml.XmlSuite;15import java.util.ArrayList;16import java.util.List;17import java.util.Map;18import java.util.HashMap;19import java.util.Iterator;20import java.util.Set;21import java.util.HashSet;22import java.util.Arrays;23import java.io.File;24import java.io.FileInputStream;25import java.io.IOException;26import java.io.InputStream;27import java.io.InputStreamReader;28import java.io.BufferedReader;29import java.io.FileInputStream;30import java.io.FileNotFoundException;31import java.io.IOException;32import java.io.InputStream;33import java.io.InputStreamReader;34import java.io.BufferedReader;35import org.apache.commons.io.FileUtils;36import org.apache.commons.io.IOUtils;37import java.util.Properties;38public class TestRunner {39 public static void main(String[] args) {40 TestNG testNG = new TestNG();41 List<String> suites = new ArrayList<String>();42 suites.add("testng.xml");43 testNG.setTestSuites(suites);44 testNG.run();45 }46}47import org.testng.TestRunner;48import org.testng.TestNG;49import org.testng.xml.XmlSuite;50import java.util.ArrayList;51import java.util.List;52import java.util.Map;53import java.util.HashMap;54import java.util.Iterator;55import java.util.Set;56import java.util.HashSet;57import java.util.Arrays;58import java.io.File;59import java.io.FileInputStream;60import java.io.IOException;61import java.io.InputStream;62import java.io.InputStreamReader;63import java.io.BufferedReader;64import java.io.FileInputStream;65import java.io.FileNotFoundException;66import java.io.IOException;67import java.io.InputStream;68import java.io.InputStreamReader;69import java.io.BufferedReader;70import org.apache.commons.io.FileUtils;71import org.apache.commons.io.IOUtils;72import java.util.Properties;73public class TestRunner {74 public static void main(String[] args) {75 TestNG testNG = new TestNG();76 List<String> suites = new ArrayList<String>();77 suites.add("testng.xml");78 testNG.setTestSuites(suites);79 testNG.run();80 }81}

Full Screen

Full Screen
copy
1public class Student {23 private int id;45 public int getId() {6 return this.id;7 }89 public setId(int newId) {10 this.id = newId;11 }12}13
Full Screen
copy
1public class Printer {2 private String name;34 public void setName(String name) {5 this.name = name;6 }78 public void print() {9 printString(name);10 }1112 private void printString(String s) {13 System.out.println(s + " (" + s.length() + ")");14 }1516 public static void main(String[] args) {17 Printer printer = new Printer();18 printer.print();19 }20}21
Full Screen
copy
1public class Test {2 public static void main(String[] args) {3 String foo = null;4 int length = foo.length(); // HERE5 }6}7
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