Priority in TestNG with multiple classes

The most correct way is to use dependsOnMethods. Priority levels are global for test (don't mix with test-methods which are annotated with @Test). In other words: when testng runs test (from <test> tag) it groups methods by priorities and then run it. In your case both testA1 and testB1 have priority=1, so will be executed at the beginning.


In your suite xml use group-by-instances="true"

Sample, where TestClass1 and TestClass2 has the same content as yours

<suite thread-count="2" verbose="10" name="testSuite" parallel="tests">
<test verbose="2" name="MytestCase" group-by-instances="true">
    <classes>
        <class name="com.crazytests.dataproviderissue.TestClass1" />
        <class name="com.crazytests.dataproviderissue.TestClass2" />
    </classes>
</test>
</suite> 

I get the output

testA1

testA2

testA3

testB1

testB2

testB3


You can just provide @Test(testName="test1") / @Test(testName="test2") at the top of each class, and the priorities will be automatically grouped per class. Of course you keep the existing annotations.

Tags:

Testng