TestNG: Changing thread counts at runtime

元气小坏坏 提交于 2019-12-24 02:25:33

问题


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

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?


回答1:


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


来源:https://stackoverflow.com/questions/26556952/testng-changing-thread-counts-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!