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

问题描述 投票:0回答:1

请帮我在测试套件中对测试进行排序。我有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

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

java testing automation testng
1个回答
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
===============================================
© www.soinside.com 2019 - 2024. All rights reserved.