如何在TestNG的XML中添加组的依赖关系

时间:2014-01-15 16:44:37

标签: xml testng

如何在TestNG的XML中添加组的依赖关系。这是我的XML

<test name="Test1">

<classes>
  <class name="test.TestNGTest1"/>
  <class name="test.TestNGTest2"/>
  <groups>
      <define name="abc">
          <include name="a"></include>
      </define>
      <define name="def">
          <include name="b"></include>
      </define>
      <run>
          <include name="def"></include>
          <include name="abc"></include>
      </run>
  </groups>
</classes>
</test>

我尝试在xml上添加组的依赖组。

2 个答案:

答案 0 :(得分:1)

您可以使用依赖项和依赖项标记(例如here)在xml中指定组依赖项。

答案 1 :(得分:0)

有两个测试类:

public class TestNGTest1 {
    @Test(groups = {"a"})
    public void test1(){}
    @Test(groups = {"b"})
    public void test2(){}
    @Test(groups = {"c"})
    public void test3(){}
    @Test(groups = {"d"})
    public void test4(){}
    @Test(groups = {"e"})
    public void test5(){}
    @Test(groups = {"f"})
    public void test6(){}
}

public class TestNGTest2 {
    @Test(groups = {"a"})
    public void test1(){}
    @Test(groups = {"b"})
    public void test2(){}
    @Test(groups = {"c"})
    public void test3(){}
    @Test(groups = {"a"})
    public void test4(){}
    @Test(groups = {"b"})
    public void test5(){}
    @Test(groups = {"c"})
    public void test6(){}
}

组的依赖关系可以通过以下方式定义:

<suite>
    <test name="Test1">
        <classes>
            <class name="test.TestNGTest1"/>
            <class name="test.TestNGTest2"/>
            <groups>
                <define name="abc">
                    <include name="a"></include>
                    <include name="b"></include>
                </define>
                <define name="def">
                    <include name="d"></include>
                    <include name="e"></include>
                </define>
                <dependencies>
                    <group name="abc" depends-on="def" />
                </dependencies>
                <run>
                    <include name="def"></include>
                    <include name="abc"></include>
                </run>
            </groups>
        </classes>
    </test>
</suite>