Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude class in TestNG?

Tags:

testng

Is this possible to exclude classes in testng.xml?

I tried with

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

but it's giving error.

like image 516
user522170 Avatar asked Aug 28 '12 10:08

user522170


People also ask

How do I exclude a class in TestNG xml?

Mention all the class names inside <classes> including the ones that should not be run. And, inside the class that should be excluded, use <methods> and <exclude name =. * />. It will exclude all the tests from this class and run all the other classes.

How do you skip a class in TestNG?

The Complete TestNG & Automation Framework Design Course If the condition meets at the time of execution, it skips the remaining code in the test. Use the parameter enabled=false at @Test. By default, this parameter is set as True. Use throw new SkipException(String message) to skip a test.

How do I exclude a group in TestNG?

Similar to this, we can ignore the groups by putting them under the "exclude" tag. This minor tweak can be seen in the XML file below. By putting our group "demo" inside the exclude tag, we are requesting TestNG to ignore the test cases under the group "demo".

How do you exclude tests in TestNG?

You can disable or exclude the test cases by using the enable attribute to the @Test annotation and assign False value to the enable attribute.


1 Answers

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.

like image 188
artdanil Avatar answered Oct 11 '22 01:10

artdanil