How to incorporate and remove test methods from execution from a collection of test cases in TestNG?

TestNGXMLJava Programming Framework

We can incorporate and remove test methods from execution with the help of <groups> tags in testng xml file.


Testng xml file.

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "" >
<suite name = "Tutorialspoint Test ">
   <test name = "Test Cycle">
            <include name = "Smoke"/>
            <exclude name = "CodingModule"/>
         <class name = "TestRegularExpression" />

The testNG xml has groups Smoke to be included and CodingModule to be excluded from the execution.


public void ContactDetails(){
   System.out.println(“Contact details verification is successful”);
public void verifyInvoice(){
   System.out.println(“Invoice verification is successful”);

In a Java class file, groups are used to pinpoint the test method. The test methods with groups as Smoke will be added in the run and CodingModule will be excluded from execution. So ContactDetails() test method shall run but verifyInvoice() shall be left out from execution.

Updated on 11-Jun-2020 12:51:12