testng.xml:
<suite name="Default Suite" parallel="classes" thread-count="3">
<test name="example">
<classes>
<class name="ExampleTest"/>
<class name="ExampleTest2"/>
</classes>
</test>
</suite>
test :
@Test(singleThreaded = true)
public class ExampleTest {
@Test
public void firstTest() {
// first test
}
@Test(dependsOnMethods = "firstTest")
public void secondTest() {
// second test depends from first test
}
}
tests run in three Threads, but the first test is in one thread, and the second in the second, respectively, the second one drops as it depends on the first one. How to run parallel tests such that all tests in one class are executed in one thread ?
Thank you in advance.
There was a bug in TestNG. Here is a link to GitHub issue.
Starting from 7.0.0-beta1 it is fixed. But you should set
-Dtestng.thread.affinity=true
as JVM argument. IntelliJ IDEA steps: go to Run -> Edit Configurations:TestClass1:
TestClass2:
TestNG XML:
Output:
P.S: If
TestClass1.test1()
fails thenTestClass1.test2()
will be ignored.