Let’s assume you have several TestNG tests in a test class.
Part of them are very stable but others are not.
Sometimes or very often our unstable tests fail. We don’t want to re-run all our tests, only tests that failed.
TestNG has the interface IRetryAnalyzer that contains only one method:
All you need is just to implement that method. If the method returns true it means the test should be re-run if failed.
Re-run failed tests 2 times example.
Different numbers of re-runs for different testes
Re-run failed tests n times if …
Specify tests that should be re-run
And the last - you can use several implementations of IRetryAnalyzer and apply different implementations for different tests.
Share how you implemented “re-run failed tests in TestNG” in the comments below or in How to re-run failed tests in TestNG using IRetryAnalyzer on GitHub.
You may also find these posts interesting: