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

This works as intended, the test fails (due to haltTesting ()) and repeats 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 since I have several tests in one class, I defined repeatAnalyzer at the 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 does not repeat, the documentation says:

The effect of class level @Test annotation is to make all public methods of this class to become test methods, even if they are not annotated. You can still repeat the @Test annotation using the method if you want to add certain attributes.

So, was this possible or am I expecting the wrong result?

+2
source share
2 answers

My solution was to set retryAnalyzer for all methods in the @BeforeSuite method. But do not set it in beforeMethod, because then it will be re-created each time it is called with a new counter => infinite loop.

 @BeforeSuite(alwaysRun = true) public void beforeSuite(ITestContext context) { TestRepeat testRepeat = new TestRepeat(); for (ITestNGMethod method : context.getAllTestMethods()) { method.setRetryAnalyzer(testRepeat); } } 
+1
source

You can implement the IAnnotationTransformer listener and the cmd list listener line in either the configuration file or at the 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 { ... } 
+2
source

Source: https://habr.com/ru/post/1202313/


All Articles