Include and exclude tags in xml

Include and exclude is used to run a few testcases out of all test cases in a class as shown in example below.

In this example we use include and exclude in xml file to decide which test cases we want to run and which we want to exclude

public class BankTests {
  @Test
  public void addBank() {
    System.out.println("In add bank test case");
  }
    
@Test
 public void addBranch() {
    System.out.println("In add branch test case");
  }
    
 @Test
    public void addAccount() {
    System.out.println("In add account test case");
  }

Above we have add three tests , 'addBank', 'addBranch' and 'addAccount' to BankTests class

In the below testng.xml file we will exclude 'addAccount' from the tests to run and that particular test will be excluded when we run the tests in the xml file

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Sample Test Suite" verbose="1" >
  <test name="Method Test Cases" >
    <classes>
       <class name="com.seleniumexample.BankTests">
        <methods>
        <include name="addBranch" />
        <include name="addBank" />
        <exclude name="addAccount" />
      </methods>
       </class>
    </classes>
  </test>
</suite>