Observe how the below tests will each be re-run once as soon as the failure happens.
import org.testng.Assert;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import org.testng.annotations.Test;
public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 1;
public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
retryCount++;
return true;
}
return false;
}
@Test(retryAnalyzer = Retry.class)
public void testGenX() {
Assert.assertEquals("test", "testFail"); // ListenerTest fails for
// james
}
@Test(retryAnalyzer = Retry.class)
public void testGenY() {
Assert.assertEquals("test", "fail"); // ListenerTest fails for
// james
}
}