本文介绍了使用具有不同优先级的testNG.xml运行多个测试类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用testNG .xml文件运行多个测试类A级'''

I am trying to run multiple test classes using testNG .xml fileClass 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");
}

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");
}

输出:它应该以测试集优先级1、2和3执行A类然后,它应该以相同的优先级1、2和3来执行Class B

Output :It should execute Class A with test set priority 1, 2 and 3Then It should execute Class B with the same Priority 1, 2 and 3

TestNG.XML'''

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>

推荐答案

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>

这篇关于使用具有不同优先级的testNG.xml运行多个测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 10:07