gpt4 book ai didi

java - 重新运行 TestNG 测试会导致测试永远运行

转载 作者:行者123 更新时间:2023-12-01 09:38:29 25 4
gpt4 key购买 nike

我有一个这样的测试:

public class Test1 extends AbstractTest{
@Test(retryAnalyzer=Retry.class)
public void test(){
System.out.println(this.getClass().getName() + " running");
Assert.fail();
}

我有一个像这样的重试类:

public class Retry implements IRetryAnalyzer{
private int retryCount = 0;
private int maxRetryCount = 3;

public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
System.out.println("Retrying test "
+ result.getName() + " with status "
+ getResultStatusName(result.getStatus())
+ " for the " + (retryCount+1) + " time(s).");
retryCount++;
return true;
}
return false;
}

public String getResultStatusName(int status) {
String resultName = null;
if(status==1)
resultName = "SUCCESS";
if(status==2)
resultName = "FAILURE";
if(status==3)
resultName = "SKIP";
return resultName;
}
}

当我运行测试时,它会无限重复,并将其作为控制台输出:

tests.Test1 running
Retrying test test with status FAILURE for the 1 time(s).
tests.Test1 running
Retrying test test with status FAILURE for the 2 time(s).
Retrying test test with status FAILURE for the 3 time(s).
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running
tests.Test1 running

等等...

为什么第二次运行失败?为什么它会无限期地运行?如何使其具有所需的运行行为,然后重试最多 3 次或我设置 MaxRetryCount 的次数?

最佳答案

关于java - 重新运行 TestNG 测试会导致测试永远运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38640056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com