问题
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