Exclude Group
TestNG also allows you to include and exclude certain groups from test execution. This helps in executing only a particular set of tests and excluding certain tests.
Lets create a java class
import org.testng.annotations.Test;
publicclass groupexample {
@Test(groups = { "functest", "exculdegroup" })
publicvoid testMethod1() {
System.out.println("This is testMethod1");
}
@Test(groups = {"exculdegroup"} )
publicvoid testMethod2() {
System.out.println("This is testMethod2");
}
@Test(groups = { "functest" })
publicvoid testMethod3() {
System.out.println("This is testMethod3");
}
}
TestNG.xml file
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none">
<testname="Test1">
<groups>
<run>
<includename="functest"/>
<excludename="exculdegroup"/>
</run>
</groups>
<classes>
<!-->class name="TestNGExample"/-->
<classname="groupexample"/>
</classes>
</test><!-- Test -->
</suite><!—Suite -->
Results
TestNG executed one methods from the group functest and excluded the two method that belonged to the group exclude-group, which was excluded from the test execution.
Note: If a test method belongs to both included and excluded group, the excluded group takes the priority and the test method will be excluded from the test execution.
Comments
Post a Comment