空手道测试框架中的重试机制

Rah*_*l R 5 karate

空手道测试框架中的重试机制 如何在空手道测试框架(如 Junit 和 TestNG)中对失败进行重试。类似公共类重试实现 IRetryAnalyzer {

private int count = 0;
private static int maxTry = 3;

@Override
public boolean retry(ITestResult iTestResult) {
    if (!iTestResult.isSuccess()) {                      //Check if test not succeed
        if (count < maxTry) {                            //Check if maxtry count is reached
            count++;                                     //Increase the maxTry count by 1
            iTestResult.setStatus(ITestResult.FAILURE);  //Mark test as failed
            return true;                                 //Tells TestNG to re-run the test
        } else {
            iTestResult.setStatus(ITestResult.FAILURE);  //If maxCount reached,test marked as failed
        }
    } else {
        iTestResult.setStatus(ITestResult.SUCCESS);      //If test passes, TestNG marks it as passed
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

}

Pet*_*mas 0

截至目前,这是一个开放的功能请求:https://github.com/intuit/karate/issues/247

但有多种解决方法。如果您查看轮询示例,您可能会得到一些想法:https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/polling/polling.feature