I have a test case like this:
@Listeners({RetryListener.class})
public class TestClass {
@Test
public void test1() throws Exception {
//something
}
@Test(dependsOnMethods = "test1")
public void test2() throws Exception {
//something
}
@Test(dependsOnMethods = "test2")
public void test3() throws Exception {
//something
}
}
As you can see, there are dependencies on the tests. I would like to retry the entire test class once there is anything wrong with the tests.
Is there a way to do it in TestNG?
My RetryListener
looks like this:
public class RetryListener extends TestListenerAdapter {
private int count = 0;
@Override
public void onTestFailure(ITestResult result) {
if (result.getMethod().getRetryAnalyzer() != null) {
Reporter.setCurrentTestResult(result);
if(result.getMethod().getRetryAnalyzer().retry(result)) {
count++;
result.setStatus(ITestResult.SKIP);
System.out.println("Error in " + result.getName() + " with status "
+ result.getStatus()+ " Retrying " + count + " of 3 times");
System.out.println("Setting test run attempt status to Skipped");
} else {
count = 0;
System.out.println("Retry limit exceeded for " + result.getName());
}
Reporter.setCurrentTestResult(null);
}
}
@Override
public void onTestSuccess(ITestResult result) {
count = 0;
}
}