I am little bit confused by this testNG behavior.
Consider this simple testNG suite. Test2 depends on Test1. The below suite also starts Test2 only after Test1 which is great!
<suite name="testng-behvaior" parallel="none">
<test name="test1">
<parameter name="browser" value="chrome" />
<classes>
<class name="com.test.Test1" />
<class name="com.test.Test2" />
</classes>
</test>
</suite>
Above suite works just fine without any issues.
But consider this. As per testNG documentation, all the <test>
would be assigned to different thread. Since i have only one <test>
, only one thread is executing this suite which is fine. But it starts with Test2 before Test1.
<suite name="testng-behvaior" parallel="tests">
<test name="test1">
<parameter name="browser" value="chrome" />
<classes>
<class name="com.test.Test1" />
<class name="com.test.Test2" />
</classes>
</test>
</suite>
For me - in the above cases, parallel="tests"
and parallel="none"
should not make any difference and behave same.
What makes testNG should behave differently? How can i have the thread to execute the <classes>
within the <test>
in sequence?
There is an attribute called preserve-order
. By default this attribute has a value of true
at both the <test>
level and at the <suite>
level.
This attribute when enabled, causes TestNG to load classes in the same order as defined in the <test>
tag and then run all the @Test
methods defined within each of them.
But for this attribute to work, you would need to disable parallelism i.e., you need to set the attribute parallel
to none
.
Only then does TestNG execute the tests in the order in which they are found in the <test>
tag.
So parallel="tests"
is NOT EQUAL TO parallel="none"