Why following code is running tests in different threads? Test class:
public class InstancesOfClass {
public static int counter=0;
public InstancesOfClass() {
counter++;
}
@Test
public void testA() {
long id=Thread.currentThread().getId();
System.out.println("A:counter="+counter+" Thread id:"+id);
}
@Test
public void testB() {
long id=Thread.currentThread().getId();
System.out.println("B:counter="+counter+" Thread id:"+id);
}
@Test
public void testC() {
long id=Thread.currentThread().getId();
System.out.println("C:counter="+counter+" Thread id:"+id);
}
}
testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="instances">
<test name="Test1" >
<classes>
<class name="InstancesOfClass"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Output:
C:counter=1 Thread id:14
B:counter=1 Thread id:13
A:counter=1 Thread id:12
In the suite I have given parallel="instances"
. counter=1
shows that there is only one instance of this test class. So why test are executing in different threads despite parallel="instances"
?