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.

MyProfile.JAVA

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

MyOrders.JAVA

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.");	
	}
	
	@Test(groups="Alpha")
	public void viewOrders()
	{
		System.out.println("View you all orders.");
	}
}

GroupExample_Basic_Suite.XML

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

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:

JIRA:

Agile:


385total visits,2visits today

Leave a Reply

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