Hello Folks,

In previous posts, we have learnt about:

Grouping test methods in TestNG

Grouping configuration methods in TestNG

We know grouping is categorization of test scripts. Let’s ask a question to yourself:

Is it possible that a test script may fall in more than one categories? Obviously Yes.

So how can we achieve same thing in TestNG? Answer is “groups attribute”.

As we have discussed , “groups” attribute is an array. Let’s see in actual code of TestNG:

Since “groups” attribute is an array, now you can pass multiple values which will be group names. If we mention 2 group names, it means that particular test method or configuration method will belong to both groups. It is “And” not “OR”.

Let’ see an example:

A TestNG class containing multiple test methods belonging to multiple groups:

TestNG XML to run methods belonging to G1:


You can see in output, methods belonging to G1 (Not only G1) are executed.

Now, here comes an interview question.

What will happen if we include multiple groups? Will same methods will run multiple times for each group names as a method”MethodsBelongToG1G2G3″ belongs to G1, G2 and G3?

Answer is No. TestNG behaves intelligently here. If will not same method multiple times for each group. It will execute once.

TestNG XML for all groups:


More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

One thought on “TestNG Tutorials 31: Multiple Groups Name For Test And Configuration Methods in TestNG

Leave a Reply