Method Grouping


You can also exclude or include individual methods:

Let’s create a java class

package testngexp;
importorg.testng.annotations.Optional;
importorg.testng.annotations.Parameters;
import org.testng.annotations.Test;
publicclass parameterizationexample {
@Test
publicvoid TestMethod1(){
System.out.println("This TestMethod1");
}
@Test
publicvoid TestMethod2(){
System.out.println("This TestMethod2");
}
@Test
publicvoid TestMethod3(){
System.out.println("This TestMethod3");
}
}

TestNG.xml

<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none"verbose="1"timeOut="1000">
<parametername="MethodName1"value="SuiteTagTestMethod1"/>
<testname="Test1">
<classes>
<classname="testngexp.parameterizationexample"/>
</classes>
<methods>
<includename="TestMethod1"/>
<includename="TestMethod2"/>
<excludename="TestMethod3"/>
</methods>
</test><!-- Test -->
</suite><!-- Suite -->

Results

image

Here, only two methods are executed, because TestMethod3 we excluded.

Comments