如何从测试套件中测试测试。

时间:2018-03-01 09:01:48

标签: java testing automation testng

请帮助我在测试套件中对测试进行排序。 我有2个测试类,每个测试类有3个测试方法。

头等舱

public class FirstClass  {

@Test(priority =1)
public void FirstMetod()
{
    System.out.println("First Method of First Class");
}


@Test(priority =2)
public void SecondMetod()
{
    System.out.println("Second Method of First Class");
}

@Test(priority =3)
public void ThirdMetod()
{
    System.out.println("Third Method of First Class");
}
}

第二课

public class SecondClass {

    @Test(priority =1)
    public void FirstMetod()
    {
        System.out.println("First Method of Second Class");
    }


    @Test(priority =2)
    public void SecondMetod()
    {
        System.out.println("Second Method of Second Class");
    }

    @Test(priority =3)
    public void ThirdMetod()
    {
        System.out.println("Third Method of Second Class");
    }
}

的testng.xml

<suite name="Suite">
<test thread-count="5" name="Test">
    <classes>
        <class name="sample.testng.FirstClass" />
        <class name="sample.testng.SecondClass" />
    </classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

结果如下。

First Method of First Class
First Method of Second Class
Second Method of First Class
Second Method of Second Class
Third Method of First Class
Third Method of Second Class

但是我需要在第一堂课后运行第二堂课。所以应该得到理想的结果。

First Method of First Class
Second Method of First Class
Third Method of First Class
First Method of Second Class
Second Method of Second Class
Third Method of Second Class

我尝试过分组并依赖于方法,但无法实现所需的序列。

1 个答案:

答案 0 :(得分:1)

priority级别移除@Test并更改您的testng.xml文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" preserve-order="true">
    <test thread-count="5" name="Test">
        <classes>
            <class name="sample.testng.FirstClass">
                <methods>
                    <include name="FirstMetod" />
                    <include name="SecondMetod" />
                    <include name="ThirdMetod" />
                </methods>
            </class>
            <class name="sample.testng.SecondClass">
                <methods>
                    <include name="FirstMetod" />
                    <include name="SecondMetod" />
                    <include name="ThirdMetod" />
                </methods>
            </class>
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

更改后,您将获得这样的输出

First Method of First Class
Second Method of First Class
Third Method of First Class
First Method of Second Class
Second Method of Second Class
Third Method of Second Class

===============================================
Suite
Total tests run: 6, Failures: 0, Skips: 0
===============================================