Groups of Groups


Groups can also include other groups. These groups are called "MetaGroups". For example, you might want to define a group "all" that includes "vssintest" and "functest". "functest" itself will contain the groups "windows" and "linux" while "vssintest will only contain "windows”.

Lets create a java file

import org.testng.annotations.Test;
publicclass groupofgroup {
@Test(groups = { "windows" })
publicvoid testWindowsOnly() {
System.out.println("This is testWindowsOnly");
}
@Test(groups = {"linux"} )
publicvoid testLinuxOnly() {
System.out.println("This is testLinuxOnly");
}
@Test(groups = { "functest"})
publicvoidtestWindowsToo() {
System.out.println("This is testWindowsToo");
}
@Test(groups = { "vssintest"})
publicvoid vssintestmethod() {
System.out.println("This is vssintestmethod");
}
}

TestNG.xml file

<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none">
<testname="Test1">
<groups>
<definename="group1">
<includename="functest"/>
<includename="vssintest"/>
</define>
<definename="group2">
<includename="windows"/>
<includename="linux"/>
</define>
<run>
<includename="group2"/>
</run>
</groups>
<classes>
<classname="groupofgroup"/>
</classes>
</test><!-- Test -->
</suite><!-- Suite -->

Result
image

TestNG executed only two methods, as mentioned in the group2 group and excluded the test methods that belong to group1. You can define as many groups of groups as you want.

Comments