TestNG retryAnalyzer only works when defined in methods @Test, does not work in class' @Test

亡梦爱人 提交于 2019-12-01 00:41:55

You can implement IAnnotationTransformer listener and register listener cmd line or in config file or at class level.

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 {
...
}
MushyPeas

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);
     }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!