0

我有一个这样的测试用例:

@Listeners({RetryListener.class})
public class TestClass {
    @Test
    public void test1() throws Exception {
        //something
    }
    @Test(dependsOnMethods = "test1")
    public void test2() throws Exception {
        //something
    }
    @Test(dependsOnMethods = "test2")
    public void test3() throws Exception {
        //something
    }
}

如您所见,测试存在依赖关系。一旦测试有任何问题,我想重试整个测试类。

有没有办法在 TestNG 中做到这一点?

我的RetryListener样子是这样的:

public class RetryListener extends TestListenerAdapter {

    private int count = 0;

    @Override
    public void onTestFailure(ITestResult result) {
        if (result.getMethod().getRetryAnalyzer() != null) {
            Reporter.setCurrentTestResult(result);

            if(result.getMethod().getRetryAnalyzer().retry(result)) {
                count++;
                result.setStatus(ITestResult.SKIP);
                System.out.println("Error in " + result.getName() + " with status "
                        + result.getStatus()+ " Retrying " + count + " of 3 times");
                System.out.println("Setting test run attempt status to Skipped");
            } else {
                count = 0;
                System.out.println("Retry limit exceeded for " + result.getName());
            }

            Reporter.setCurrentTestResult(null);
        }
    }

    @Override
    public void onTestSuccess(ITestResult result) {
        count = 0;
    }
}
4

0 回答 0