How to exclude class in TestNG?

2019-02-06 10:19发布

Is this possible to exclude classes in testng.xml?

I tried with

<packages>
    <package exclude="com.tt.ee"/>
</packages>

but it's giving error.

标签: testng
7条回答
迷人小祖宗
2楼-- · 2019-02-06 10:57

According to the TestNG dtd, the exclude element is only applicable to the following elements:

  • package - The package description within packages list.
  • methods - The list of methods to include/exclude from this test.
  • run - The subtag of groups used to define which groups should be run.

The elements classes and class cannot be directly excluded; however, you can exclude classes through groups:

@Test(groups = { "ClassTest1" })
public class Test1 {

  public void testMethod1() {
  }

  public void testMethod2() {
  }

}

Then you will define the testng.xml:

<suite>
  <test>
    <groups>
      <run>
        <exclude name="ClassTest1"/>
      </run>
    </groups>
    <classes>
      <class name="Test1">
    </classes>
  </test> 
</suite>

In most cases you define, which classes to include for the run, not to exclude, so just include the classes you want to run.

查看更多
登录 后发表回答