Java TestNG-configfailurepolicy=";“继续”;不适用于重试的测试
尽管configfailurepolicy值设置为“continue”,但将跳过重试的测试 示例: testng.xml-在套件级别,configfailurepolicy值设置为“continue” RetryAnalyzer:如果发生故障,将重试一次Java TestNG-configfailurepolicy=";“继续”;不适用于重试的测试,java,testng,testng.xml,Java,Testng,Testng.xml,尽管configfailurepolicy值设置为“continue”,但将跳过重试的测试 示例: testng.xml-在套件级别,configfailurepolicy值设置为“continue” RetryAnalyzer:如果发生故障,将重试一次 import org.testng.IRetryAnalyzer; import org.testng.ITestResult; public class RetryAnalyzer implements IRetryAnalyzer {
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class RetryAnalyzer implements IRetryAnalyzer {
private int counter = 0;
private int retryLimit = 1;
@Override
public boolean retry(ITestResult result) {
if (counter < retryLimit) {
counter++;
return true;
}
return false;
}
}
import org.testng.IRetryAnalyzer;
导入org.testng.ITestResult;
公共类RetryAnalyzer实现IRetryAnalyzer{
专用整数计数器=0;
私人int retryLimit=1;
@凌驾
公共布尔重试(ITestResult结果){
如果(计数器
结果:由于@AfterMethod失败,重试测试,但跳过@test。因此,“方法”不会打印在第5行的结果中
方法之前
方法
后置法
方法之前
后置法
方法1
后置法
预期结果:由于configfailurepolicy配置为“继续”,因此不应跳过重试测试。因此,应在第5行的结果中打印预期的“方法”,如下所示
方法之前
方法
后置法
方法之前
方法
后置法
方法1
后置法
7.1.0版本的TestNG解决了这个问题 Ref:在github提出了一个问题。
import org.testng.Assert;
import org.testng.annotations.Test;
public class ExcepionAfterMethodTest{
@BeforeMethod(alwaysRun=true)
public void beforeMethod() {
System.out.println("Before Method");
}
@Test (alwaysRun=true, retryAnalyzer=RetryAnalyzer.class)
public void method() {
System.out.println("Method");
Assert.assertTrue(false);
}
@Test (alwaysRun=true)
public void method1() {
System.out.println("Method1");
}
@AfterMethod(alwaysRun=true)
public void afterMethod() throws Exception {
System.out.println("After Method");
throw new Exception();
}
}
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class RetryAnalyzer implements IRetryAnalyzer {
private int counter = 0;
private int retryLimit = 1;
@Override
public boolean retry(ITestResult result) {
if (counter < retryLimit) {
counter++;
return true;
}
return false;
}
}