TestNg Groups

Knoldus Inc.
Knoldus - Technical Insights
2 min readJun 21, 2016

Grouping is very good feature of testng. Its a next generation testing techniques. In previous blog we learn what is TestNg, how to execute Testng program etc. Now we explain how to make groups in testng.

Benefits of grouping: Suppose we have 100 test methods in a single test class and we defined some high priority test methods and some low priority test methods.From these method we want to run only high priority test methods. So we can easily make the groups for it.

We will create test case and we will defined some methods where we can defined high, low priority.

Here is the code:

[code language=”Scala”]
import org.testng.annotations.Test;
public class TestGroup1 {
@Test(priority=0,groups = {“high”})
public void login()
{
System.out.println(“Do login”);
}
@Test(priority=1, groups = {“low”})
public void fillform()
{
System.out.println(“fill the form”);
}
@Test(priority=2, groups = {“high”})
public void searchdata()
{
System.out.println(“serach the flights”);
}
@Test(priority=3, groups = {“medium”})
public void enddata()
{
System.out.println(“end flight”);
}
}
[/code]

For grouping we have to define groups in testing.xml.Here we run the only high priority test methods.

[code language=”text”]
<test name=”Testing group1" >
<classes>
<class name=”TestGroup1"/>
</classes>
</test>
<groups>
<run>
<include name =”high”/>
</run>
</groups>
[/code]

In testing xml we defined <groups> and <run> tag. <groups> tag defines the group and </run> tag represents the group that needs to be run.

testng result

We can easily see the html report which is generated by testng.

testng report

login and search data are the high priority groups so when define high priority groups in testng.xml it run the only high priority groups test methods.

--

--

Knoldus Inc.
Knoldus - Technical Insights

Group of smart Engineers with a Product mindset who partner with your business to drive competitive advantage | www.knoldus.com