如何避免重试添加测试注释?
How to avoid Retry adding in Test annotation?
我遇到了关于如何在 Selenium 网络驱动程序测试中使用 Retry
的答案。现在我已经在实用程序下和下面给出的测试注释中实现了 Retry class @Test(retryAnalyzer = Retry.class)
。这现在工作正常,但我想改变这种方式,我可以以任何其他方式使用重试而不是将测试注释作为 @Test(retryAnalyzer = Retry.class)
给出吗?我还需要评论 @Test(enabled = true)
,有人可以指教吗?
utilities/Retry
class
public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 2;
public boolean retry(ITestResult result) {
if(retryCount < maxRetryCount) {
retryCount ++ ;
return true;
}
return false;
}
}
tests/RepaymentCalculatorTest
public class RepaymentCalculatorTest extends BaseTest {
Retry retryTest = new Retry();
//@Test(enabled = true)
@Test(retryAnalyzer = Retry.class)
public void loanRepaymentCalculator() throws InterruptedException {
// rest of the UI test code added here ....
}
我使用的方式有点不同,不需要在@Test注解中添加class
让我们为它定制监听器
public class RetryFailedTestCases implements IRetryAnalyzer, IAnnotationTransformer{
public void transform(ITestAnnotation testannotation, Class testClass, Constructor testConstructor,
Method testMethod) {
testannotation.setRetryAnalyzer(RetryFailedTestCases.class);
}
int counter = 0;
int retryLimit = 1; //as per need
@Override
public boolean retry(ITestResult result) {
if(counter < retryLimit)
{
counter++;
return true;
}
return false;
}
}
现在,将其添加到 testng.xml 文件
<listeners>
<listener class-name="package.RetryFailedTestCases"/>
</listeners>
当我们 运行 作为套件时,这很简单而且很有帮助.. 或者我们可以在每个 class 的顶部提到监听器 class 而不是 testng.xml 文件
我不确定为什么明确提到 enabled = true ?即使不@Test 执行对吗?如果您不想执行,请用 false 提及。
我遇到了关于如何在 Selenium 网络驱动程序测试中使用 Retry
的答案。现在我已经在实用程序下和下面给出的测试注释中实现了 Retry class @Test(retryAnalyzer = Retry.class)
。这现在工作正常,但我想改变这种方式,我可以以任何其他方式使用重试而不是将测试注释作为 @Test(retryAnalyzer = Retry.class)
给出吗?我还需要评论 @Test(enabled = true)
,有人可以指教吗?
utilities/Retry
class
public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 2;
public boolean retry(ITestResult result) {
if(retryCount < maxRetryCount) {
retryCount ++ ;
return true;
}
return false;
}
}
tests/RepaymentCalculatorTest
public class RepaymentCalculatorTest extends BaseTest {
Retry retryTest = new Retry();
//@Test(enabled = true)
@Test(retryAnalyzer = Retry.class)
public void loanRepaymentCalculator() throws InterruptedException {
// rest of the UI test code added here ....
}
我使用的方式有点不同,不需要在@Test注解中添加class
让我们为它定制监听器
public class RetryFailedTestCases implements IRetryAnalyzer, IAnnotationTransformer{
public void transform(ITestAnnotation testannotation, Class testClass, Constructor testConstructor,
Method testMethod) {
testannotation.setRetryAnalyzer(RetryFailedTestCases.class);
}
int counter = 0;
int retryLimit = 1; //as per need
@Override
public boolean retry(ITestResult result) {
if(counter < retryLimit)
{
counter++;
return true;
}
return false;
}
}
现在,将其添加到 testng.xml 文件
<listeners>
<listener class-name="package.RetryFailedTestCases"/>
</listeners>
当我们 运行 作为套件时,这很简单而且很有帮助.. 或者我们可以在每个 class 的顶部提到监听器 class 而不是 testng.xml 文件
我不确定为什么明确提到 enabled = true ?即使不@Test 执行对吗?如果您不想执行,请用 false 提及。