Grouping of Tests in TestNG

  • Estimate Completion Time
    not found 30 minutes
  • Difficulty Level:

Write a TestNG test method to categorize into groups using TestNG and control which groups are to be executed.

Steps to follow

Create new TestNG class named “GroupTestDemo”.

Create 3 test methods ‘groupATest()’, ‘groupBTest()’, ‘groupBothTest()’.

Categorize these methods into groups: ‘groupATest()’ to group “A”, ‘groupBTest()’ to group “B” and ‘groupBothTest()’ to both groups.

Configure the XML file to run only the “A” group. Execute the test suite and observe that only two methods run.

Solution

package practice;
import org.testng.annotations.Test;
public class GroupTestDemo {
@Test(groups = "A")
	public void groupATest() {
		System.out.println("This is Group A");
	}
	
	
	@Test(groups = "B")
	public void groupBTest() {
		System.out.println("This is Group B");
	}
	@Test(groups = {"A","B"})
public void groupBothTest() {
		System.out.println("This is Group A and Group B both");
	}
}
<suite name=”Suite”>
<test name="GroupATests">
<groups>	 
   <run>  
          <include name="A"/>  
    </run>  
</groups>
	 <classes>
	    <class name="testngNotes.Names"></class>
	  </classes>
  </test> 
  </suite>
TestNG Practice Exercises - QA Ads Banner

Proleed Academy

Proleed serves / offers professionally designed IT training courses
globally.

Copyright © 2023 - Proleed Academy | All Rights Reserved.