TestNG:全局设置调用计数 [英] TestNG: Set invocationCount globally

查看:30
本文介绍了TestNG:全局设置调用计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望多个包中的所有测试(假设 100 个测试,每个类 1 个)运行 3 次.我可以设置

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)

但这仍然需要一百个改变.有没有办法在单个抽象类中设置 invocationCount(或其他参数),而无需将其添加到每个 @Test 中?

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?

推荐答案

像这样构建一个注解转换器实现

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

然后,您可以使用套件 xml 文件中的 <listener> 标记(或)通过创建服务加载器文件 META-INF/services/org.testng 来连接此侦听器.ITestNGListener,然后将 Transformer 的条目添加到此文件中.

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.

这篇关于TestNG:全局设置调用计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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