1

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] -->
2
  • Thanks man! one more addition - still feeling fixed is not perfectly tuned. Expecting one more update. Lets see ! Aug 9, 2016 at 11:01
  • Why do you mean by feeling is not perfectly tuned?
    – tetienne
    Aug 11, 2016 at 13:29

1 Answer 1

1

You can run only failed test cases explicitly without any code. This can be easily done by running one simple testng-failed.xml

Steps:

  1. If your test cases are failing then once all test suite completed then you have to refresh your project .

    • Right click on project
    • Click on refresh or
    • Select project and press f5.
  2. Check test-output folder,

    • at last, you will get testng-failed.xml
  3. Now simply run testng-failed.xml

Updated after knowing version used is 6.9.10

  • Version you are using is having open issues
  • Due to that issue testng-failed.xml itself is not generated properly

Work around -

  1. Can you try 6.9.11-SNAPSHOT? Its working for me
  2. You can force your TestNG eclipse plugin to start using the TestNG jar available in your CLASSPATH by doing the following :
    • Project > Properties > TestNG > Use project testng jar
  3. Uncheck that option & run the tests with 6.9.11-SNAPSHOT in my pom.xml

Please crosscheck once. Hope it helps you!

10
  • It's exactly what I did. My issue is this testng-failed.xml is not properly created. Look at it.
    – tetienne
    Aug 8, 2016 at 9:24
  • Are you using TestNG 6.3.1? Aug 8, 2016 at 9:32
  • Yes the latest.
    – tetienne
    Aug 8, 2016 at 9:55
  • This is not the latest one - can you share your TestNG version? Its lot related to version & answer could differ for different version Aug 8, 2016 at 10:14
  • Sorry, I answered too quickly. I use the 6.9.10 version.
    – tetienne
    Aug 8, 2016 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.