问题
I am trying to run multiple test classes using testNG .xml file Class A '''
@Test( priority = 1 )
public void testA1() {
System.out.println("testA1");
}
@Test( priority = 2 )
public void testA2() {
System.out.println("testA2");
}
@Test( priority = 3 )
public void testA3() {
System.out.println("testA3");
}
Class B '''
@Test( priority = 1 )
public void testA1() {
System.out.println("testA1");
}
@Test( priority = 2 )
public void testA2() {
System.out.println("testA2");
}
@Test( priority = 3 )
public void testA3() {
System.out.println("testA3");
}
Output : It should execute Class A with test set priority 1, 2 and 3 Then It should execute Class B with the same Priority 1, 2 and 3
TestNG.XML '''
<suite name="REGRESSION_TEST_SET" thread-count="1" parallel="tests" >
<test name="AUTOMATION" group-by-instances="true">
<classes>
<class name="ClassA" />
<class name="ClassB" />
</classes>
</test>
</suite>
回答1:
For running all test method of one class first and then for the other classes, testng.xml file structure needs to be changed. You need to specify test method from each class in the order of their execution.
Without this change, xml file will run as per priority ex testA1() and then testB1().
Please find the xml file required to achieve tests class wise :
<suite name="REGRESSION_TEST_SET" thread-count="1" parallel="tests" >
<test name="AUTOMATION" group-by-instances="true">
<classes>
<class name="ClassA" />
<methods>
<include name="testA1"/>
<include name="testA2"/>
<include name="testA3"/>
</methods>
</class>
<class name="ClassB" />
<methods>
<include name="testB1"/>
<include name="testB2"/>
<include name="testB3"/>
</methods>
</class>
</classes>
</test>
来源:https://stackoverflow.com/questions/62759696/run-multiple-test-classes-using-testng-xml-with-different-priority