【发布时间】:2014-10-07 15:37:31
【问题描述】:
我有一个测试,invocationcount 设置为 20,如果迭代 4 或 5 失败,我希望测试停止。
有什么办法吗?我只是在谷歌上搜索了相同的内容,但找不到任何内容
【问题讨论】:
标签: testng
我有一个测试,invocationcount 设置为 20,如果迭代 4 或 5 失败,我希望测试停止。
有什么办法吗?我只是在谷歌上搜索了相同的内容,但找不到任何内容
【问题讨论】:
标签: testng
您可以使用IInvokedMethodListener。
覆盖接口的两种方法。在 afterInvocation 中,检查结果并可能添加到 Map<method, failureCount> 的映射中
在 beforeInvocation 中,检查 failureCount > 4 然后抛出 SkipException,将导致其余调用被跳过。
类似:
static Map<String, Integer> methodFailCount = new HashMap<String, Integer>();
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
if(methodFailCount.get(method.getTestMethod().getMethodName())!= null && methodFailCount.get(method.getTestMethod().getMethodName()) > 4)
throw new SkipException("Skipped due to failure count > 4");
}
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
if(testResult.getStatus() == TestResult.FAILURE){
if(methodFailCount.get(method.getTestMethod().getMethodName() ) == null)
methodFailCount.put(method.getTestMethod().getMethodName(),1);
else{
methodFailCount.put(method.getTestMethod().getMethodName(),
methodFailCount.get(method.getTestMethod().getMethodName() )+1);
}
}
}
【讨论】: