Rerun All Failed Testcases using TestNG

Use Case:
While running automation suite, there may be few failures based on quality of build received or because of issue with automation script, in such cases after fixes, you may just want to rerun failed testcases rather than rerunning full suite depending on reasons like reproduce failures, fast conclusion on fix provided, time constraint etc.
If you want to retry a testcase multiple times before reporting failure than read this.

Every time tests fail in a suite, TestNG creates a file called testng-failed.xml in the output directory. This XML file contains the necessary information to rerun only these methods that failed.

So, If you are running your test suite from Command Line
Similar to your test run invoca tion with testNG.xml, assuming TestNG jar is available in your classpath, you need to invoke test suite with testng-failed.xml as following:

java org.testng.TestNG testng-failed.xml

If you are running your test suite from Eclipse
Just right click on testng-failed xml, and Run As TestNG Suite. By default you will find testng-failed.xml under test-output folder.

If you are running your test suite using Maven
then you must be specifying testng.xml in your pom.xml as following:
instead of testng.xml, provide testng-failed.xml as suiteXMLFile.