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.


Testng xml files with groups.

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "" >
<suite name = "Tutorialspoint Test">
   <test name = "Regression Cycle 1">
            <include name = "QuestionAnswer"/>
            <include name = "Jobs"/>
         <class name = "TestParam" />

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.


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