Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 28: Grouping Test Methods In TestNG

Posted on 04/23/2025 By admin

Hello Folks,

In this post, we will learn about grouping of test methods in TestNG.

“Group” is meant for categorisation of similar items. In a supermarket, you see how they separate different types of vegetables to make it easier for customers to locate them (As shown in above pic).

Similar concept we apply for test cases. We group test cases based on modules name, suite name etc. We group test cases in Smoke , Sanity, Regression suites etc and whenever required we execute those suites. If you need to execute test cases of module “UserAccess”, you find out test cases which belong to group “UserAccess” and run it. You can decide easily what to run and not to run.

TestNG provides you rich options to group your scripts. We will explore those concepts in this post.

Grouping in TestNG:

  • “groups” is an attribute provided by TestNG which can be used for @Test annotated methods, Configuration methods and at class level. By using it, you can specify to which group/groups , this class or methods belong to.
  • “groups” attribute is a String array. It means you can tag multiple groups to a method or class.
  • You can specify which groups to include, exclude in testng xml explicitly using include and exclude tags.
  • If you do not mention anything, by default it will run for all groups.

Syntax:

groups = {“G1”} ==> Single group
groups = {“G1″,”G2″,”G3”} ==> MUltiple groups 

In this post, we will see grouping of test methods. Groping of configuration methods and classes will be in upcoming posts.

Example:

Let’s create a TestNG class containing test methods of three groups as:

Create a testng.xml as below:

If you run above xml , you will get below output:

You will find it as normal execution output.

Now consider, you just need to execute test methods belong to group “G1”. You have two options to do this: 1. Mark all methods of remaining groups (G2,G3 in this case) as “enabled=false”.

2. Only include/exclude desired group/s in testng.xml

Uncategorized

Post navigation

Previous Post: Postman Tutorial Part 26 – Using Environment in Collection Runner
Next Post: Controlling Browser Driver Services In Selenium WebDriver

Related Posts

Why And How Should We Terminate Browser Driver Executable File In Selenium WebDriver Uncategorized
June 20, 2017 – Make Selenium Easy Uncategorized
Postman Tutorial Part 15 – Adding Automation Test Scripts In Postman Uncategorized
Launch of Firefox Browser through Selenium 3: | Make Selenium Easy Uncategorized
Hierarchy of Classes & Interfaces of WebDriver Interface in Selenium WebDriver – Make Selenium Easy Uncategorized
REST Assured Tutorial 45 – Fetch Value From Nested JSON Object Using JsonNode – Jackson – at() Method Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark