Partial Groups
You can define groups at the class level and then add groups at the method level
Lets create java class
import org.testng.annotations.Test;
@Test(groups = { "ClassGroup"} )
publicclasspartialgroups {
@Test(groups = { "methodgroup"} )
publicvoid method1() {
System.out.println("This is method1");
}
publicvoid method2() {
System.out.println("This is method2");
}
}
In this class, method2() is part of the group "classgroup", which is defined at the class level, while method1() belongs to both "classgroup" and "methodgroup".
TestNG.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none">
<testname="Test1">
<groups>
<run>
<includename="ClassGroup"/>
</run>
</groups>
<classes>
<!-->class name="TestNGExample"/-->
<classname="partialgroups"/>
</classes>
</test><!-- Test -->
</suite><!-- Suite -->
Results
Will run both the methods(method1 and method2) because in testng.xml we are calling classgroup , so both methods are belongs to classgroup even method1 is defined in methodgroup
Lets see another example
TestNG.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none">
<testname="Test1">
<groups>
<run>
<includename="methodgroup"/>
</run>
</groups>
<classes>
<!-->class name="TestNGExample"/-->
<classname="partialgroups"/>
</classes>
</test><!-- Test -->
</suite><!-- Suite -->
Results
Will run only method1 because in testng.xml we are calling methodgroup
Comments
Post a Comment