如何在 TestNG 开始时获得测试总量(包括考虑数据提供者)? [英] How to get total amount of tests (incl. taking data providers into account) at TestNG start?

查看:22
本文介绍了如何在 TestNG 开始时获得测试总量(包括考虑数据提供者)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何在 TestNG(套件)启动时获取(预期)所有测试/方法执行的计数?

Can anyone tell me how to get (expected) count of all tests / method executions at TestNG (suite) start?

您可以轻松获取所有测试方法的数量,但这不会计算每个测试方法乘以数据提供者大小的数量(每个方法都会计算一次,即使一个方法通过数据执行了 100 次)提供者).

You can easily get the amount of all test methods, but this doesn't count each test method times the amount of the data provider size (each method will be counted once, even if one method is executed 100 times via a data provider).

除非有一个明显的解决方案,比如一个简单的API调用,关键似乎是从@Test注释中给出的数据提供者名称中找出数据提供者方法,我在这里问:如何从TestNG数据提供者获取数据提供者方法名字?

Unless there is an obvious solution to this, like a simple API call, the key seems to be to figure out the data provider method from the data provider name given in the @Test annotation, which I asked here: How to get data provider method from TestNG data provider name?

一旦你知道数据提供者方法是什么,你就可以执行数据提供者,并计算数据集的数量.这似乎不是很有效,但我们运行的测试不是单元测试,所以我不会太担心两次执行数据提供者(与实际测试运行的时间相比,这将是一个花生).

Once you know what the data provider method is, you could execute the data provider, and count the amount of data sets. This doesn't seem very efficient, but the tests we're running are not unit tests, so I wouldn't be too worried about executing the data providers twice (it will be a peanut compared to how long the actual tests run).

推荐答案

在试运行中尝试实现 IInvokedMethodListener 并覆盖 beforeInvocation 方法

In dry run try to implement IInvokedMethodListener and override beforeInvocation method

public class Test implements IInvokedMethodListener
{
    static int testcount=0;
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
            
            testcount=testcount+method.getTestMethod().getInvocationCount();
    }

    @Override
    public void onStart(ISuite suite) {
        // TODO Auto-generated method stub
        
    }

    
    @Override
    public void onFinish(ISuite suite) {
        System.out.println(testcount);
        
    }
}

这篇关于如何在 TestNG 开始时获得测试总量(包括考虑数据提供者)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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