How to combine multiple groups to 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: 11-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements