0
我已經使用IRetryAnalyzer重新運行失敗的測試用例。我還使用IAnnotationTransformer作爲TestNg Listener。現在只有最後一次重新運行的測試用例在報告中失敗了。以前的迭代即將跳過。我希望所有的迭代都會在報告中失敗。重新運行失敗的測試用例在testng報告中顯示status ='Skipped'
下面是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