Parallel=instances run tests of same instance on different threads
See original GitHub issueThe documentation says that • parallel=“instances”: TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.
However test methods for the same instances are running on different threads. Please see https://github.com/nmanandhar/TestNGParallelBehaviorTest.git
public class TestClassA {
private static AtomicInteger instanceCount = new AtomicInteger(0);
public TestClassA() {
instanceCount.incrementAndGet();
log("A new instance of TestClassA created");
}
@AfterSuite
public void printNumberOfInstances() {
log("Number of instances of TestClassA = " + instanceCount.get());
}
@Test
public void testA1() throws Exception {
log("testA1 of TestInstance " + this);
}
@Test(dependsOnMethods = "testA1")
public void testB1() {
log("testB1 of TestInstance " + this);
}
@Test(dataProvider = "integerProvider")
public void testDataProvider(int number) throws Exception {
log("testDataProvider : number = " + number + " testInstance = " + this);
}
@DataProvider
public Object[][] integerProvider() {
return new Object[][]{
{1},
{2}
};
}
private void log(String message) {
String threadName = Thread.currentThread().getName();
synchronized (System.out) {
System.out.println(String.format("Thread %s : %s ", threadName, message));
}
}
}
Suite File
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="InstanceTestSuite" parallel="instances" thread-count="5">
<test name="InstanceTest">
<classes>
<class name="com.nm.TestClassA"/>
</classes>
</test>
</suite>
Output of mvn test
Running TestSuite
Thread main : A new instance of TestClassA created
Thread pool-1-thread-1 : testA1 of TestInstance com.nm.TestClassA@58ee2549
Thread pool-1-thread-1 : testDataProvider : number = 1 testInstance = com.nm.TestClassA@58ee2549
Thread pool-1-thread-1 : testDataProvider : number = 2 testInstance = com.nm.TestClassA@58ee2549
Thread pool-1-thread-2 : testB1 of TestInstance com.nm.TestClassA@58ee2549
Thread main : Number of instance = 1
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.835 sec - in TestSuite
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:28
Top Results From Across the Web
Why parallel="instances" running tests within same class ...
counter=1 shows that there is only one instance of this test class. So why test are executing in different threads despite parallel="instances" ...
Read more >Executing Parallel Tests in TestNG - PawanGaria.com
To Run Test Class parallel meaning each Class will be executed in a different Thread and the same thread is used for Test...
Read more >Parallel Test Execution in Selenium using TestNG - H2k Infosys
Parallel Testing is a technique where you want to run multiple tests simultaneously in different threads to reduce the execution time.
Read more >Parallel Test Execution in Selenium using TestNG
parallel = “instances “: TestNG will run all test cases in the same instance in the same thread, but two methods on two...
Read more >Parallelization with TestNG - Robust Test Automation with Java
instances, TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mihalyr @krmahadevan Both of you are right: the feature is working as expected except when a dependency feature is involved. It is a known issue and it should be fixed. But the current implementation won’t allow it easily and nobody has currently enough free time to dig and fix it. I suppose the documentation should be improved with a link to this issue to warn about the issue.
Thanks, was not sure if it affected both parallel instances and classes. Thanks for the links to the code, I’ll try to find some time to look into.