Include and Exclude Test Methods in TestNG With Example

.

 Include and Exclude Test Cases in TestNG With Example

Include Mechanism

Let's Understand the include scenarios

if we have to execute only one test case (Method) of any class we can use the include method. if a java class has multiple test cases (method) and we have to execute only one then we use include in XML File.


Selenium Code

package testNGPackage;


import org.testng.annotations.Test;


public class SecondTestngClass {

@Test

public void usersignin() {

System.out.println("user Sign in");

}

@Test

public void membersingin() {

System.out.println("This is Member singin");

}

@Test

public void customersingin() {

System.out.println("This Customer signin");

}

}



XML File 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite">

<test name="homeloan">

<classes>

<class name="testNGPackage.SecondTestngClass">

<methods>

<include name="usersignin"></include>

</methods>

</class>

<class name="testNGPackage.FirstTestngClass"/>

</classes>

</test> <!-- Test -->

</suite> <!-- Suite -->



Exclude Mechanism 

If we have to not execute one or more test cases from any class then we use exclude.

In the below example, we will not execute the usersignin method from the class for this we have written exclude function in the XML file.

Selenium Code 

package testNGPackage;


import org.testng.annotations.Test;


public class SecondTestngClass {

@Test

public void usersignin() {

System.out.println("user Sign in");

}

@Test

public void membersingin() {

System.out.println("This is Member singin");

}

@Test

public void customersingin() {

System.out.println("This Customer signin");

}

}

XML File

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite">

<test name="homeloan">

<classes>

<class name="testNGPackage.SecondTestngClass">

<methods>

<exclude name="usersignin"></exclude>

</methods>

</class>

<class name="testNGPackage.FirstTestngClass"/>

</classes>

</test> <!-- Test -->

</suite> <!-- Suite -->


The above XML File will exclude the Method (usersignin)  and all other Methods of the class will execute successfully.


Hope!!! The above Tutorial include and exclude in testng helpful for you...


Team,

QA acharya


Tags: Include and exclude in testng XML , Include and Exclude Test Methods in TestNG , Include & Exclude mechanism in TestNG


Include and Exclude Test Methods in TestNG With Example


Post a Comment

0 Comments