TestNG Groups | TestNG Tutorial

TestNG Groups:

TestNG allows you to perform sophisticated groupings of test methods. Not only can you declare that methods belong to groups, but you can also specify groups that contain other groups. Then TestNG can be invoked and asked to include a certain set of groups (or regular expressions) while excluding another set.  This gives you maximum flexibility in how you partition your tests and doesn’t require you to recompile anything if you want to run two different sets of tests back to back.

Groups are specified in your testng.xml file and can be found either under the <test> or <suite> tag. Groups specified in the <suite> tag apply to all the <test> tags underneath.

Here is a video tutorial to learn “TestNG Groups”:

Please be patient. The video “TestNG Groups” will load in some time.

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

Script – Test Case 1:

Script – Test Case 2:


Console Output:

Group of Groups in TestNG Groups:

Groups can also include other groups. These groups are called MetaGroups. For example, you might want to define a group all that includes smokeTest and functionalTest. Let’s modify our testng.xml file as follows:

testng.xml – Group of Groups:

Console Output:

Groups Exclusion:

TestNG allows you to include groups as well as exclude them. You can ignore a group by using the <exclude> tag as shown below:

Here is a video tutorial to learn “Exclusion of Groups in TestNG”:

Please be patient. The video will load in some time.

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

For example, it is quite usual to have tests that temporarily break because of a recent change, and you don’t have time to fix the breakage yet. However, you do want to have clean runs of your functional tests, so you need to deactivate these tests but keep in mind they will need to be reactivated.

Console Output:

You can also disable tests on an individual basis by using the “enabled” property available on both @Test and @Before/After annotations.

Check this post – How to Ignore TestNG Tests.

You could find the complete TestNG tutorial here.

TestNG Complete Tutorial

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

testng groups

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

4 thoughts on “TestNG Groups | TestNG Tutorial”

  1. Hello Sir,

    Can you please make the font size more in Eclipse, i could’t able to see the text

    • Sure Rajini, we will try to do it in upcoming videos.

  2. Hello Sir,

    I am trying to revoke TestNG via testng.xml ….but after right click on “run as” my eclipse dont show the option of run as TestNG Suit. FYI, I created maven project and already have selenium and testng jars downloaded..

    • Hi Priyanka,
      Try to create a new xml file.. follow the below xml file. Change package name and class names..

Leave a Comment

Share via
Copy link
Powered by Social Snap