Andrejs
Andrejs

Reputation: 11901

TestNG: Set invocationCount globally

I want all my tests (let's say 100 tests, 1 per class) in several packages to run 3 times. I can set

@Test(invocationCount = SOME_CONSTANT)

But that would still require a hundred changes. Is there a way to set an invocationCount (or other params) in a single abstract class without resorting to adding this to every @Test?

Upvotes: 2

Views: 1038

Answers (1)

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14736

Build an annotation transformer implementation such as this

public class Transformer implements IAnnotationTransformer {

    @Override
    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
        int someNumber = 100;
        annotation.setInvocationCount(someNumber);
    }
}

You then wire in this listener either using the <listener> tag in the suite xml file (or) by creating the service loader file META-INF/services/org.testng.ITestNGListener and then adding an entry for Transformer into this file.

For more information on listeners you can take a look at this blog post of mine.

Upvotes: 4

Related Questions