我使用IRetryAnalyzer来重新运行我失败的测试用例。我还使用IAnnotationTransformer作为TestNg Listener。现在,只有重新运行的测试用例的最后一个计数在报告中失败。之前的迭代将被跳过。我希望所有的迭代都应该在报告中失败。
以下是2个类的代码:
对于IAnnotationTransformer:
package com.TestNG;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.IRetryAnalyzer;
import org.testng.annotations.ITestAnnotation;
public class RetryListener implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation testannotation, Class testClass,
Constructor testConstructor, Method testMethod) {
IRetryAnalyzer retry = testannotation.getRetryAnalyzer();
if (retry == null) {
testannotation.setRetryAnalyzer(Retry.class);
}
}
}
对于IRetryAnalyzer:
package com.TestNG;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 2;
@Override
public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
retryCount++;
return true;
}
return false;
}
}
结果: Screenshot