Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

java - 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

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

@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. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
     }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...