In last post, we learnt about Multiple groups names foe test and configuration methods.
When we assign a method to multiple groups, you find difficulties when you want to run methods belong to only particular groups or to only some groups.
For example: Suppose There are three methods M1 ( belongs to G1), M2(Belongs to G1 and G2) and M3(G1, G2 and G3). If you want to run methods which only belongs to G1 ( not G2 or G3), you will find it difficult to call in testng xml.
We will see an example below:
Now I want TestNG to run methods which belongs to only group G1 i.e. MethodsBelongToG1 . If we create testng xml as below:
Here we did not expect above result. We wanted only “MethodsBelongToG1” to run but it ran all methods which belong to G1.
How to achieve that now?
You just need to exclude remaining groups in testng xml as below:
Now we got desired output.
If you want to run methods which belong to either only G1 or G2, you need to add groups in testng xml as below:
But above approach will not work if you want to run methods which belong to G1 and G2 together i.e. not only to G1 or G2. We have a solution for that which we will see in next posts.
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.
Author: Amod Mahajan
A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.