TestNG:全局设置调用计数

编程入门 行业动态 更新时间:2024-10-28 04:23:02
本文介绍了TestNG:全局设置调用计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我希望多个包中的所有测试(假设 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 22:00:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1401157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   TestNG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!