Skip to content Skip to navigation
Check Our New Demo Website!

Groups in TestNG

TestNG allows us to perform sophisticated groupings of test methods.

Using TestNG we can execute only set of groups while excluding another set. This gives us the maximum flexibility in divide tests and doesn't require us to recompile anything if you want to run two different sets of tests back to back.

Groups are specified in testng.xml file and can be used either under the or tag. Groups specified in the tag apply to all the tags underneath.

package com.example.group;
import org.testng.annotations.Test;
public class groupExamples {
	@Test(groups="Regression")
	public void testCaseOne()
	{
	System.out.println("Im in testCaseOne - And in Regression Group");
	}
	@Test(groups="Regression")
	public void testCaseTwo(){
	System.out.println("Im in testCaseTwo - And in Regression Group");
	}
	@Test(groups="Smoke Test")
	public void testCaseThree(){
	System.out.println("Im in testCaseThree - And in Smoke Test Group");
	}
	@Test(groups="Regression")
	public void testCaseFour(){
	System.out.println("Im in testCaseFour - And in Regression Group");
	}
}

The below is the XML file to execute, the test methods with group.
We will execute the group “Regression” which will execute the test methods which are defined with group as “Regression”

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Sample Suite">
  <test name="testing">
  	<groups>
      <run>
        <include name="Regression"/>
      </run>
    </groups>
    <classes>
       <class name="com.example.group.groupExamples" />
    </classes>
  </test>
</suite>
Test Frameworks: 

Comments

It was really fantastic site. Thanks for Author.

Better to provide subscribe newsletter option for this website, If any new article published then subscribed users will get an alert. Please try to implement the same.

In the same way, Better to bring updates on latest trends in software testing...

I was going through the Selenium and TestNG tutorials and got to admit the content quality is pretty good. The tutorials are simple, easy to understand and at the same time covers the topic thoroughly. It has helped me a lot. Thanks!

I like this post, it is so meanful.

Great Platform for the beginners like me who wants to gain continuous knowledge in an interesting way with practical examples....!! kudo's and thanks a lot for the team who have been involved in spending their qualitative time in dedicate for this site.

Thanks to author for providing detailed explanation for every concept.

super!

This is really use full site to understand topics

Thanks a lot.

Thank you so much .I was really facing this problem tha how to execute in groups.Finally find out this blog.its very nice and meaningful.
Thank you so much .

Let me explain you mine case.
I want to do sanity testing for online shopping website.
Sanity includes : login with valid user >> go to product details page >> add product into cart >> go to cart page >> do checkout >> create new order.

I have POM classes for every page. Like Login page, Product detail page, cart page, checkout page etc
and I have test classes for each page like LoginPageTest , CartPagetest etc which contains all test cases(positive and negative) belonging to that respective pages.

Now i want to execute all positive test cases for my sanity testing.
please guide me how will I use this group annotation.

Pages

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.