【问题标题】:exclude multiple groups TestNG排除多个组 TestNG
【发布时间】:2017-04-22 01:12:02
【问题描述】:
public class c1 {

@Test(groups ={"first","third"})
public void p1_c1_1()
{
    System.out.println("p1_c1_1");

}
@Test(groups ="second")
public void p1_c1_2(){

    System.out.println("p1_c1_2");
}
@Test(groups ="third")
public void p1_c1_3(){

    System.out.println("p1_c1_3");
}


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite One" allow-return-values="true" verbose="1">
<test name="Test One">
    <groups>
        <define name="all">
            <include name="first" />
            <exclude name="second"/>
            <exclude name="third"/>
        </define>
        <run>
            <include name="all" />
        </run>
    </groups>
    <classes>
        <class name="c1" />
    </classes>
</test>
</suite>

如果我运行这个 testNg 文件,我会打印出 p1_c1_1,我不能这样做,因为它在“第一”和“第二”两个组下。因此,尽管 p1_c1_1 位于名为“first”的包含组下,但它仍位于名为“third”的排除组下,因此从技术上讲,该方法不应被执行。我想知道如何排除两个组下的方法,其中一个组包括在内

【问题讨论】:

    标签: unit-testing testing automation testng


    【解决方案1】:

    dtd 指定 &lt;define&gt; 只支持包含作为选项

    <!ELEMENT groups (define*,run?,dependencies?) >
    
    <!ELEMENT define (include*)>
    <!ATTLIST define
        name CDATA #REQUIRED>
    

    因此,实现这一目标的唯一方法是运行简单组,而不是定义一组组。即

    <groups>
            <run>
                 <include name="first" />
                <exclude name="second"/>
                <exclude name="third"/>
            </run>
        </groups>
    

    这将按照您想要的方式工作。因为在这个例子中至少没有复杂的分组,所以在这种情况下甚至不需要元组。

    【讨论】:

      【解决方案2】:

      如果您想尝试根据组进行更复杂的过滤,也许您可​​以尝试在您的 TestNG 套件 XML 文件中利用 Beanshell 功能,您可以在其中定义您想要的任何内容。

      有关如何在 TestNG 套件 xml 文件中利用 Beanshell 的更多信息,您可以查看我的 this 博客文章。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-22
        相关资源
        最近更新 更多