TestNG retryAnalyzer 仅在方法@Test 中定义时有效,在类@Test 中无效
这按预期工作,测试失败(由于 haltTesting())并重复 2 次p>
This works as supposed, test fails (due to haltTesting()) and is repeated 2x
public class A0001_A0003Test extends TestControl {
private Kunde kunde = Kunde.FR_WEHLITZ;
@Test(retryAnalyzer = TestRepeat.class, groups = {TestGroups.FAILED}, description = "verify adress")
public void testkundenDaten_Angaben() throws Exception {
bifiTestInitial();
testActions.selectKunde(kunde);
haltTesting();
}
}
但是因为我在一个班级中有多个测试,所以我在班级级别定义了 repeatAnalyzer
but because i have multiple tests in one class, i defined the repeatAnalyzer on class level
@Test(retryAnalyzer = TestRepeat.class)
public class A0001_A0003Test extends TestControl {
private Kunde kunde = Kunde.FR_WEHLITZ;
@Test(groups = {TestGroups.FAILED}, description = "verify adress")
public void testkundenDaten_Angaben() throws Exception {
bifiTestInitial();
testActions.selectKunde(kunde);
haltTesting();
}
}
但是没有重复测试,文档说:
but then the test is not repeated, the documentation says:
一个类级别的@Test注解的作用是使所有的此类的公共方法成为测试方法,即使它们是没有注释.您仍然可以在方法上重复 @Test 注释如果你想添加某些属性.
The effect of a class level @Test annotation is to make all the public methods of this class to become test methods even if they are not annotated. You can still repeat the @Test annotation on a method if you want to add certain attributes.
所以这应该是可能的,还是我期待错误的结果?
So it should have been possible or am I expecting the wrong outcome?
推荐答案
我的解决方案是为 @BeforeSuite
方法中的所有方法设置一个 retryAnalyzer.但是不要在 beforeMethod 中设置它,因为这样每次调用都会重新创建一个新的计数器 => 无限循环.
My solution was to set a retryAnalyzer for all methods in the @BeforeSuite
method.
But do not set it in beforeMethod because then it will be re-created each invocation with a new counter => endless loop.
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext context) {
TestRepeat testRepeat = new TestRepeat();
for (ITestNGMethod method : context.getAllTestMethods()) {
method.setRetryAnalyzer(testRepeat);
}
}
相关文章