在@Test方法来定义时TestNG的retryAnalyzer只能,在课堂上不工作'@Test [英] TestNG retryAnalyzer only works when defined in methods @Test, does not work in class' @Test

查看:922
本文介绍了在@Test方法来定义时TestNG的retryAnalyzer只能,在课堂上不工作'@Test的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这工作像预想的那样,测试失败(由于haltTesting()),反复2次

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?

推荐答案

我的解决办法是设置一个retryAnalyzer在 @BeforeSuite 方法的所有方法。
但不要将其设置成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) {
     for (ITestNGMethod method : context.getAllTestMethods()) {
         method.setRetryAnalyzer(new TestRepeat());
     }
}

这篇关于在@Test方法来定义时TestNG的retryAnalyzer只能,在课堂上不工作'@Test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆