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?
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.
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.
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 ...
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With