Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude packages from TestNG

Consider the following TestNG configuration which runs all tests in the com.example.functional.* pacakge:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Functional1" verbose="1" >
  <test name="FunctionalTest"   >
    <packages>
      <package name="com.example.functional.*">
      </package>
    </packages>
  </test>
</suite>

In order to split the test job, some exclusion rules were added:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Functional1" verbose="1" >
  <test name="FunctionalTest"   >
    <packages>
      <package name="com.example.functional.*">
            <exclude name="com.example.functional.services.courier.*"></exclude>
            <exclude name="com.example.functional.optimization.*"></exclude>
            <exclude name="com.example.functional.initialization"></exclude>
            <exclude name="com.example.functional.tasks"></exclude>
      </package>
    </packages>
  </test>
</suite>

The excluded package are still being executed - any idea why the exclusions are ignored?

like image 404
Adam Matan Avatar asked Jun 10 '13 07:06

Adam Matan


People also ask

How do you ignore packages and classes in TestNG?

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 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.

What is include and exclude in TestNG?

Include and Exclude tags are used in TestNG to include and exclude Test Methods. They could also be used to include and exclude packages, classes and groups within a class file. To keep it simple we will use an example class file with three methods from which we will see how to include and exclude Test Methods in a ...


1 Answers

The * is the problem. When excluding optimization.*, sub-packages of optimization are excluded, but optimization isn't.

Removing * from the exclude tags should do it:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Functional1" verbose="1" >
  <test name="FunctionalTest"   >
    <packages>
      <package name="com.example.functional.*">
            <exclude name="com.example.functional.services.courier"></exclude>
            <exclude name="com.example.functional.optimization"></exclude>
            <exclude name="com.example.functional.initialization"></exclude>
            <exclude name="com.example.functional.tasks"></exclude>
      </package>
    </packages>
  </test>
</suite>
like image 69
Dooomer Avatar answered Sep 17 '22 17:09

Dooomer