testng-调用计数-第一次失败时停止测试

testng-调用计数-第一次失败时停止测试,testng,Testng,我有一个invocationcount设置为20的测试,如果迭代4或5失败,我希望测试停止 有什么办法吗?我只是在谷歌上搜索了一下,但没有找到任何你可以利用的 重写接口的两个方法。在afterInvocation中,检查结果并可能添加到map 在beforeInvocation中,检查failureCount>4然后抛出SkipException是否会导致跳过其余调用 比如: static Map<String, Integer> methodFailCount = new Hash

我有一个
invocationcount
设置为20的测试,如果迭代4或5失败,我希望测试停止

有什么办法吗?我只是在谷歌上搜索了一下,但没有找到任何你可以利用的

重写接口的两个方法。在afterInvocation中,检查结果并可能添加到
map

在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);
            }

        }   

    }
static Map methodFailCount=new HashMap();
调用前公共无效(IInvokedMethod方法,ITestResult testResult){
if(methodFailCount.get(method.getTestMethod().getMethodName())!=null&&methodFailCount.get(method.getTestMethod().getMethodName())>4)
抛出新SkipException(“由于失败计数>4而跳过”);
}
调用后公共void(IInvokedMethod方法,ITestResult testResult){
if(testResult.getStatus()==testResult.FAILURE){
if(methodFailCount.get(method.getTestMethod().getMethodName())==null)
methodFailCount.put(method.getTestMethod().getMethodName(),1);
否则{
methodFailCount.put(方法.getTestMethod().getMethodName(),
methodFailCount.get(method.getTestMethod().getMethodName())+1);
}
}   
}

太棒了!这很有帮助