Combine Multiple Groups into a Single Test in TestNG



We can combine multiple groups to single Test in TestNG with the help of test group feature.

Example

Testng xml files with groups.

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "Tutorialspoint Test">
   <test name = "Regression Cycle 1">
      <groups>
         <run>
            <include name = "QuestionAnswer"/>
         </run>
         <run>
            <include name = "Jobs"/>
         </run>
      </groups>
      <classes>
         <class name = "TestParam" />
      </classes>
   </test>
</suite>

To run a group of test cases from the collection of test cases, we have to define <groups> in the testng xml file. Here the testNG xml contains multiple groups QuestionAnswer and Jobs to be associated to a single Test.

Example

@Test(groups={"QuestionAnswer"},{"Jobs"})
public void preparation(){
   System.out.println("Preparation module is verified");
}

In the Java class file the test methods with group as QuestionAnswer and Jobs are associated with the test method preparation().

Updated on: 2020-06-11T12:59:31+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements