如何使用testNG使用“skipFailedInvocations”和“retryAnalyzer”?

时间:2016-10-26 15:44:42

标签: java selenium-webdriver testng

我们如何使用testNG将"skipFailedInvocations""retryAnalyzer" @Test 注释结合使用?

请求您提供示例。

1 个答案:

答案 0 :(得分:1)

示例代码:

演示测试类:

public class DemoClass{

@Test(skipFailedInvocations=true, retryAnalyzer=RetryAnalyzer.class)
public void test(){
    Assert.assertTrue(false);
}

}

重试分析器类:

public class RetryAnalyzer implements IRetryAnalyzer  { 
private int count = 0; 
private int maxCount = 4; // set your count to re-run test

public boolean retry(ITestResult result) { 
        if(count < maxCount) {                     
                count++;                                    
                return true; 
        } 
        return false; 
}
}

<强>说明:

如果skipFailedInvocations的值设置为true,则调用计数(此处为RetryAnalyzer类中的maxCount)为&gt; 1,然后失败后的所有调用将被标记为SKIP而不是FAIL。