I recently migrate from Junit to TestNg. Currently, I try to understand how to rerun the failed test.
According, I've just to run my test suite then recall TestNG with the testng-failed file. Easy.
But, here my experience. I ask to TestNG to run only one class, with 5 tests where one is KO.
Now see my testng-failed.xml files
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="3" verbose="0" name="Failed suite [Surefire suite]">
<test name="Surefire test">
<classes>
<class name="com.corp.qa.spec.TestLogin"/>
</classes>
</test> <!-- Surefire test -->
<test name="Surefire test(failed)">
<classes>
<class name="com.corp.qa.spec.TestLogin">
<methods>
<include name="openLoginPage"/>
<include name="die"/>
<include name="loginAsManager"/>
</methods>
</class> <!-- com.corp.qa.spec.TestLogin -->
</classes>
</test> <!-- Surefire test(failed) -->
</suite> <!-- Failed suite [Surefire suite] -->
TestNG create a test suite where the whole class will be run, then the @BeforeMethod (openLoginPage), the @AfterMethod (die), and finally the failing method.
I missed something? I expected to only see
<classes>
<class name="com.corp.qa.spec.TestLogin">
<methods>
<include name="loginAsManager"/>
</methods>
</class> <!-- com.corp.qa.spec.TestLogin -->
Edit: After updating TestNG to 6.9.12, failed tests file is correcly set.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="1" verbose="0" name="Failed suite [Surefire suite]">
<test name="Surefire test(failed)">
<classes>
<class name="com.corp.qa.spec.TestLogin">
<methods>
<include name="die"/>
<include name="openLoginPage"/>
<include name="loginAsManager"/>
</methods>
</class> <!-- com.corp.qa.spec.TestLogin -->
</classes>
</test> <!-- Surefire test(failed) -->
</suite> <!-- Failed suite [Surefire suite] -->