TestNG:在运行时更改线程数 [英] TestNG: Changing thread counts at runtime

查看:207
本文介绍了TestNG:在运行时更改线程数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个可以并行或串行执行的套件.但是,这样做的决定将保留到运行时.启动此套件的常见方法如下:

Suppose that I have a suite which can be executed either in parallel or serially. However, the decision to do so is left until runtime. The common way of starting this suite would be something like:

TestNG runner = new TestNG();
if (runInParallel()) {
    // set parallel mode too here
    runner.setThreadCount(2);
}
// ...
runner.run();

我现在想知道是否可以做同样的事情,但是里面有设置线程数"逻辑,例如ISuiteListner或其他合适的侦听器.如果我要使用ISuiteListener,并使用其onStart()来操纵ISuite后面的XmlSuite并在那里设置线程数,那么在运行测试时是否会尊重它们?还是一旦执行了套件侦听器,您就被有效地锁定在任何已经设置的并发设置上?

I'm now wondering if it is possible to do the same, but with the "set thread count" logic inside, say, an ISuiteListner or other suitable listener. If I were to use an ISuiteListener, and use its onStart() to manipulate the XmlSuite behind an ISuite and set the thread counts there, would they be respected when the tests are run? Or is it the case that once you are executing the suite listeners, you are effectively locked to whatever concurrency settings are already in place?

推荐答案

我在@BeforeSuite带注释的方法中做了类似的将并发属性的事情,并且有效.

I did something similar will parallel attribute in @BeforeSuite annotated method and it works.

@BeforeSuite
public void beforeSuite(ITestContext context)
{
    context.getSuite().getXmlSuite().setParallel(System.getProperty("parallel", "false"));
}

因此,可以假设它应适用于线程数以太

So, can assume that it should work for thread-count ether

context.getSuite().getXmlSuite().setThreadCount(10);

这篇关于TestNG:在运行时更改线程数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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