Grouping of Test Cases in TestNG

In the previous post, we have seen how to prioritize the test cases in TestNG. In this post, we will learn about Grouping of Test Cases in TestNG.

In TestNG , we have one more annotation known as “Groups” which can be used to executed multiple test cases belong to the same group. Suppose, you have 100 test cases related to “Bank”. Now, out of 100, 50 are related to HDFCBank, 20 are related to ICICIBank, 10 are related to SBIBank and so on. There might be requirement that you have to execute test cases only related to HDFCBank. This can be possible by using annotation “Groups“.

How to implement it ?

For understanding its implementation, let’s create the 2 groups HDFCBank and SBIBank. A bank can have different branches in other areas but each branck will belong to the same bank. Likewise, we have create some test as shown below. Branch1 and Branch2 belong to the group HDFCBank , Branch3 and Branch4 belong to group SBIBank. We have one more method Branch5  which belongs to 2 groups “HDFCBank” and “Bank“.

Syntax: (groups = { ” Group Name” })


Right click on testng.xml and run it as testng suite.

Output in console:

Group run in testng

Result of running suite: 

Group testng result


As you can see that we have included only HDFCBank group in testng.xml , so it has executed only those test cases Branch1 and Branch2. Branch5 is also executed, because it also has group “HDFCBank” along with another group “Bank”.

Now, if we want to run all the groups. Then , we can add all the groups in testng.xml.

Run the suite and you will get the result as below. This time all the test cases will be executed.

Run all group in TestNG


This is box title
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Prioritizing of Test Cases in TestNG
Skip test case and create dependency in TestNG
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *