3
votes

Is there a reason why maven would not run my AfterClass which is set to alwaysRun=true? BeforeClass is run without issues and test passes according to surefire report. I run command in terminal:

mvn -Dtest=TestSuite2#test_case3 test

and get

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:10.228s
[INFO] Finished at: Wed Nov 13 18:24:07 EET 2013
[INFO] Final Memory: 14M/114M
[INFO] ------------------------------------------------------------------------

The problem is though that my AfterClass, where I quit driver (driver.quit()) is not run. Everything works as expected, if I run the same test via Eclipse with TestNG (right click on the method, run as TestNG test)

1
Currently I can only solve this by changing AfterClass to AfterSuite - casper
Can you please show your class structure, with method names and annotations? - Jordão
I'm running into this same issue, with AfterSuite methods too. I have a BaseTestCase with my before and after suite methods, which is then extended by each of my test classes. The AfterSuite annotations are set to alwaysRun=true, but I'm not seeing my clean up occurring.. - Dave Birch
you can try it with AfterTest and BeforeTest instead of AfterClass and BeforeClss. - SahilPatel

1 Answers

0
votes

It works in IDE (Eclipse/IDEA) because it creates testng.xml and run test against it. You need to check pom.xml and revise your Maven Surefire Plugin configuration.