TestNG – 11 || Groups attribute with @Test Annotation.

Groups attribute is used to create groups using various methods from multiple Classess. Mainly this attribute is used with @Test Annotations.

Grouping of Test methods using groups attribute.

In the above example, we have created two groups Alpha and Regression. In the Alpha group, we have added all the methods from both the classes(myProfile.java and myOrders.java). On the other hand, we have marked one method from each class under Regression group.

User can call any group using <groups> tag under testsuite.xml file.

  • myProfile.java
    • VerifyProfile()
    • ViewProfile()
    • UpdateProfile()
  • myOrders.java
    • VerifyOrders
    • ViewOrders

Groups Attribute

To understand the above process let’s move into the code and structure of each file.


package groupExample;
import org.testng.annotations.Test;
 * @author ashok.kumar
public class MyProfile {
	public void verifyProfile()
		System.out.println("MyProfile button is active.");
	@Test(groups= {"Alpha","Regression"})
	public void viewProfile()
		System.out.println("View MyProfile Page.");
	public void updateProfile()
		System.out.println("Profile updated successfully.");


package groupExample;
import org.testng.annotations.Test;
 * @author ashok.kumar
public class MyOrders {
	@Test(groups= {"Regression","Alpha"})
	public void VerifyOrders()
	   System.out.println("Orders buttons is working.");	
	public void viewOrders()
		System.out.println("View you all orders.");


<?xml version="1.0" encoding="UTF-8"?>
<suite name="GroupExample_Basic_Suite">
<test name="Test1">
			<include name="Alpha"/>
		<class name="groupExample.MyOrders"/>
		<class name="groupExample.MyProfile"/>

Result Analysis

Test Result in index.html format when “Alpha” group is called.

Result of Alpha Group.

Test Result in index.html format when “Regression” group is called.

Result of Regression Group.

Related Links:

Computer Basics:

Java Basics:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:

Selenium Tutorials:



Leave a Comment

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

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.