Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
How to run multiple test classes in TestNG?
testng.xml has a format as
Here, we will have two classes with multiple test methods, and we will see how testng.xml is configured to run both the classes - NewTestngClass and OrderofTestExecutionInTestNG.
Approach/Algorithm to solve this problem
Setp 1 − Create two TestNG classes - NewTestngClass and OrderofTestExecutionInTestNG.
Setp 2 − Write two different @Test method in both the classes - NewTestngClass and OrderofTestExecutionInTestNG.
Setp 3 − Now create the testNG.xml as given below.
Setp 4 − Now, run the testNG.xml or directly testNG class in IDE or compile and run it using command line.
Example
The following code shows how to run multiple classes −
src/ NewTestngClass.java
import org.testng.annotations.Test;
public class NewTestngClass {
@Test
public void testCase1() {
System.out.println("in test case 1 of NewTestngClass");
}
@Test
public void testCase2() {
System.out.println("in test case 2 of NewTestngClass");
}
}
src/OrderofTestExecutionInTestNG.java
import org.testng.annotations.Test;
public class OrderofTestExecutionInTestNG {
// test case 1
@Test
public void testCase3() {
System.out.println("in test case 3 of OrderofTestExecutionInTestNG");
}
// test case 2
@Test
public void testCase4() {
System.out.println("in test case 4 of OrderofTestExecutionInTestNG");
}
}
testng.xml
This is a configuration file that is used to organize and run the TestNG test cases. It is very handy when limited tests are needed to execute rather than the full suite.
Output
in test case 1 of NewTestngClass in test case 2 of NewTestngClass in test case 3 of OrderofTestExecutionInTestNG in test case 4 of OrderofTestExecutionInTestNG =============================================== Suite1 Total tests run: 4, Passes: 4, Failures: 0, Skips: 0 ===============================================
