我有许多使用testNG的Java片状测试,这些测试可能会随机失败。现在,我想重复运行它们,直到失败,并看到日志输出。testNG能做到这一点吗?
似乎有许多关于如何重试失败测试的问题,但是关于如何在失败之前重新尝试测试却没有解决方案。
发布于 2022-11-15 06:07:13
考虑使用testNG的重试分析器。
public class MyRetryAnalyzer implements IRetryAnalyzer {
@Override
public boolean retry(ITestResult result) {
// analyze the result and return true if you want to rerun the test
// return false other
}
}public class MyTest {
@Test(retryAnalyzer = MyRetryAnalyzer.class)
public void sampleTest()
{
....
}请参阅有关此功能这里的示例。
发布于 2022-11-15 10:36:11
有一次做了类似的事情,我建议您做一个while循环,它将运行测试直到出现故障。
当出现故障时,更改标志状态,这将有助于停止循环。
boolean flag = true;
while (flag){
// Run Test
// and if test fail change flag
flag = false ;
}
Assert.assertTrue(flag);https://stackoverflow.com/questions/74441166
复制相似问题