Executing failed tests in testng

Most of the times, we have to run only the failed tests because due to shaky environment, some tests might fail. TestNG provides a feature that allows us to execute only failed tests. After the test suite is executed, TestNG creates one file in the output directory with name as testng-failed.xml. All you have to do is execute this file to run failed tests. If you are using Maven as your build management system, you will find that file under target/surefire-reports directory. Here is the sample XML file containing failed test configuration that was created by TestNG. Note that after executing this file, only failed tests will be executed.
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite guice-stage="DEVELOPMENT" verbose="0" name="Failed suite [Suite]" parallel="classes">
  <test name="Tests">
    <classes>
      <class name="org.softpost.Class1"/>
      <class name="org.softpost.Class2"/>
    </classes>
  </test> <!-- Tests -->
  <test name="Tests(failed)" parallel="classes">
    <classes>
      <class name="org.softpost.Class2">
        <methods>
          <include name="test1"/>
        </methods>
      </class> <!-- org.softpost.Class2 -->
      <class name="org.softpost.Class1">
        <methods>
          <include name="test1"/>
        </methods>
      </class> <!-- org.softpost.Class1 -->
    </classes>
  </test> <!-- Tests(failed) -->
</suite> <!-- Failed suite [Suite] -->     

Web development and Automation testing

solutions delivered!!