Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
Grouping of Test Cases in TestNG - Testingpool

Grouping of Test Cases in TestNG

In the previous post, we have seen how to prioritize the test cases in TestNG. In this post, we will learn about Grouping of Test Cases in TestNG.

In TestNG , we have one more annotation known as “Groups” which can be used to executed multiple test cases belong to the same group. Suppose, you have 100 test cases related to “Bank”. Now, out of 100, 50 are related to HDFCBank, 20 are related to ICICIBank, 10 are related to SBIBank and so on. There might be requirement that you have to execute test cases only related to HDFCBank. This can be possible by using annotation “Groups“.

How to implement it ?

For understanding its implementation, let’s create the 2 groups HDFCBank and SBIBank. A bank can have different branches in other areas but each branck will belong to the same bank. Likewise, we have create some test as shown below. Branch1 and Branch2 belong to the group HDFCBank , Branch3 and Branch4 belong to group SBIBank. We have one more method Branch5  which belongs to 2 groups “HDFCBank” and “Bank“.

Syntax: (groups = { ” Group Name” })

import org.testng.annotations.Test;

public class GroupExample {

	@Test(groups={"HDFCBank"})
	public void Branch1(){
		System.out.println("Test 1 : HDFC Branch");
	}
	
	@Test(groups={"HDFCBank"})
	public void Branch2(){
		System.out.println("Test 2 : HDFC Branch");
	}
	
	@Test(groups={"SBIBank"})
	public void Branch3(){
		System.out.println("Test 3 : SBI Branch");
	}
	
	@Test(groups={"SBIBank"})
	public void Branch4(){
		System.out.println("Test 4 : SBI Branch");
	}
	
	@Test(groups={"HDFCBank","Bank"})
	public void Branch5(){
		System.out.println("Test 4 : HDFC Branch and Main Bank");
	}
}

testng.xml: 

<suite name="ExampleTestSuite" >
  <test name="Bank functionality">
  <groups>
  	<run>
  	  <include name="HDFCBank"/>
  	</run>
  </groups>
    <classes>
      <class name="com.testsuite.example.GroupExample"/>
    </classes>
  </test>
</suite>

Right click on testng.xml and run it as testng suite.

Output in console:

Group run in testng

Result of running suite: 

Group testng result

 

As you can see that we have included only HDFCBank group in testng.xml , so it has executed only those test cases Branch1 and Branch2. Branch5 is also executed, because it also has group “HDFCBank” along with another group “Bank”.

Now, if we want to run all the groups. Then , we can add all the groups in testng.xml.

<suite name="ExampleTestSuite" >
  <test name="Bank functionality">
  <groups>
  	<run>
  	  <include name="HDFCBank"/>
  	  <include name="SBIBank"/>
  	</run>
  </groups>
    <classes>
      <class name="com.testsuite.example.GroupExample"/>
    </classes>
  </test>
</suite>

Run the suite and you will get the result as below. This time all the test cases will be executed.

Run all group in TestNG


 

This is box title
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...