Multiple class execution using TestNG xml

One of the important feature of running test cases from testng.xml is that we can execute test cases from multiple classes in one go. We can include multiple classes together. Below is the simple example of testng xml file which includes multiple classes.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Package Execution Suite">
  <test name="Package Execution">
  <classes>
  	<class name="com.qatechhub.testng.package1.TestClass1"></class>
  	<class name="com.qatechhub.testng.package1.TestClass2"></class>
  </classes>
  </test>
</suite>

Here, in above xml file, there are two classes which are included in classes tag namely TestClass1 and TestClass2.

Code for TestClass1:

package com.qatechhub.testng.package1;

import org.testng.annotations.Test;

public class TestClass1 {
	@Test
	public void tc1(){
		System.out.println("Executing testcase1 of testclass1..");
	}
	
	@Test
	public void tc2(){
		System.out.println("Executing testcase2 of testclass1..");
	}
	
	@Test
	public void tc3(){
		System.out.println("Executing testcase3 of testclass1..");
	}

}

Code for TestClass2:

package com.qatechhub.testng.package1;

import org.testng.annotations.Test;

public class TestClass2 {
	@Test
	public void tc1(){
		System.out.println("Executing testcase1 of testclass2..");
	}
	
	@Test
	public void tc2(){
		System.out.println("Executing testcase2 of testclass2..");
	}
	
	@Test
	public void tc3(){
		System.out.println("Executing testcase3 of testclass2..");
	}

}

Result of above Execution:

packageExecution

HTML report for above execution:

report

PS: For any questions queries or comment feel free to write us at saurabh@qatechhub.com or support@qatechhub.com. Happy Learning 🙂

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: