Run Multiple test classes using testNG.xml with different priority

廉价感情. 提交于 2021-01-29 20:55:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!