[英]TestNG retryAnalyzer only works when defined in methods @Test, does not work in class' @Test
This works as supposed, test fails (due to haltTesting()) and is repeated 2x 这按预期工作,测试失败(由于haltTesting()),并重复了2次
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();
}
}
but because i have multiple tests in one class, i defined the repeatAnalyzer on class level 但是由于我在一班中有多个测试,所以我在班级定义了repeatAnalyzer
@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: 但是文档中没有重复进行测试,而是说:
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. 类级别的@Test注释的作用是使该类的所有公共方法都成为测试方法,即使它们没有被注释也是如此。 You can still repeat the @Test annotation on a method if you want to add certain attributes. 如果要添加某些属性,仍可以在方法上重复@Test批注。
So it should have been possible or am I expecting the wrong outcome? 所以应该是可能的,还是我期望错误的结果?
You can implement IAnnotationTransformer listener and register listener cmd line or in config file or at class level. 您可以实现IAnnotationTransformer侦听器并在配置文件中或在类级别注册侦听器cmd行。
public class MyAnnotationTransformer implements
IAnnotationTransformer {
@Override
public void transform(ITestAnnotation testAnnotation, Class clazz, Constructor testConstructor,
Method method) {
testAnnotation.setRetryAnalyzer(TestRepeat.class);
}
...
}
To register at class level: 要在课程级别注册:
@Listeners(value=MyAnnotationTransformer.class)
public class A0001_A0003Test extends TestControl {
...
}
My solution was to set a retryAnalyzer for all methods in the @BeforeSuite
method. 我的解决办法是设置一个retryAnalyzer在所有方法@BeforeSuite
方法。 But do not set it in beforeMethod because then it will be re-created each invocation with a new counter => endless loop. 但是不要在beforeMethod中设置它,因为这样每次调用时都会使用新的counter => endless loop重新创建它。
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext context) {
TestRepeat testRepeat = new TestRepeat();
for (ITestNGMethod method : context.getAllTestMethods()) {
method.setRetryAnalyzer(testRepeat);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.