TestNG: Set invocationCount globally

2019-09-16 11:03发布

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?

标签: testng
1条回答
倾城 Initia
2楼-- · 2019-09-16 11:23

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.

查看更多
登录 后发表回答