2

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?

Kelvin Chung
  • 1,327
  • 1
  • 11
  • 23

1 Answers1

2

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);
user1058106
  • 530
  • 3
  • 12