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:

testng.xml:

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.

Sharing is caring.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

4 thoughts on “TestNG Groups | TestNG Tutorial”

  1. 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..

Leave a Comment

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

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp

Recent Posts:

Scroll to Top
API Testing eBook

DOWNLOAD FOR FREE