Reputation: 305
I have a test like this:
public class Test1 extends AbstractTest{
@Test(retryAnalyzer=Retry.class)
public void test(){
System.out.println(this.getClass().getName() + " running");
Assert.fail();
}
I have a retry class like this:
public class Retry implements IRetryAnalyzer{
private int retryCount = 0;
private int maxRetryCount = 3;
public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
System.out.println("Retrying test "
+ result.getName() + " with status "
+ getResultStatusName(result.getStatus())
+ " for the " + (retryCount+1) + " time(s).");
retryCount++;
return true;
}
return false;
}
public String getResultStatusName(int status) {
String resultName = null;
if(status==1)
resultName = "SUCCESS";
if(status==2)
resultName = "FAILURE";
if(status==3)
resultName = "SKIP";
return resultName;
}
}
When I run the test, it repeats indefinitely, giving this as console output:
tests.Test1 running
Retrying test test with status FAILURE for the 1 time(s).
tests.Test1 running
Retrying test test with status FAILURE for the 2 time(s).
Retrying test test with status FAILURE for the 3 time(s).
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
And so forth...
Why does it fail to run the second time? Why does it run indefinitely? How can I make it have the desired behavior of running, then retrying up to 3 times or however many i set MaxRetryCount to?
Upvotes: 0
Views: 142
Reputation: 5740
Try the latest because it is supposed to work: https://github.com/cbeust/testng/blob/master/src/test/java/test/retryAnalyzer/RetryAnalyzerTest.java
Upvotes: 1