TestNG Tutorials 38: How to Execute Groups in TestNG without Using TestNG XML

Hello folks,

In this post, we will see something new related to grouping in TestNG.

When we assign group or groups to test methods in TestNG, to include or exclude groups to run we use TestNG xml. Do you know that we can run groups without TestNG xml and can include, exclude groups easily compare to updation in TestNG xml? Yes, we can do. Let’s see how.

Create some TestNG classes as below:

I created two packages and one class in each package. Each class contains three methods which belong to different groups.

Class “GroupingExample1FromP1” from package “GroupsExamplePackage1”:

Class “GroupingExample1FromP2” from package “GroupsExamplePackage2”:

So we have 6 groups total from both packages. G1FromP1, G2FromP1, G3FromP1, G1FromP2, G2FromP2 and G3FromP2.

Now we will run these groups without creating testng xml. Steps are as follows:

Step 1: Navigate to Run-> Run Configurations:

Step 2: Click on TestNG on Left side of run configuration:

Note : You need to expand TestNG. If you have any existing testng.xml click on that to see next step’s screen. If you do not have any existing testng xml, create any testng xml and then repeat above steps again and click on newly created testng xml left side.

Step 3: Select your project:

Step 4: After selecting project, you will see “Groups” under Run header. Click on radio button of “groups”.

Step 5: Click on “Browse” button, You will see all group names there from all packages of project:

Step 6: Select groups which you want to run and click on Ok button:

Step 7: Click on Apply – > Run :

Output:

You can see methods from selected group run. There is no need to use include or exclude tags. This is very useful while creating scripts, quick run of some group scripts etc to test or debug.

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.
#ThanksForReading
#HappySelenium

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning