简体   繁体   English

TestNG retryAnalyzer仅在方法@Test中定义时起作用,而在类的@Test中不起作用

[英]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.

相关问题 TestNG:RetryAnalyzer,如果重试成功则跳过依赖组 - TestNG: RetryAnalyzer, dependent groups are skipped if a test succeeds upon retry 在仅访问TestNG中该类的特定组时执行该类的所有测试方法 - Executing all test methods of a class while accessing only particular group of that class in TestNG TestNG 仅在每个 class 上运行第一次测试 - TestNG is only running first test on each class 如何只执行测试 class 和 TestNG 中的第一个测试 - How to only execute the first test in a Test class with TestNG 在TestNG中开始上课之前获取当前的类测试方法 - Get current class test methods before class started in TestNG 当TestNG.xml仅具有类列表而不具有方法列表时,可以通过编程方式调用@Test方法吗? - Can I call @Test method programmatically when TestNG.xml has list of classes only not methods? 在TestNG测试套件的类中获取_all_方法的列表 - Getting list of _all_ methods in a class for a TestNG test suite 我们可以在任何测试类中使用在testng侦听器中定义的变量吗? - Can we use variables defined in testng listeners in any of the test class? 在所有类@Test方法之后但在TestNG中的@AfterGroups之前运行代码 - Run code after all class @Test methods but before @AfterGroups in TestNG @test 注释如何在 testNG 中工作? - How the @test annotation works in testNG?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM