- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to run multiple test classes in TestNG?
testng.xml has a format as <classes> where we define what all test classes should be executed. Users can mention n number of classes in testing.xml that require executing. In this article, we are going to discuss how to execute more than one class using a single testing.xml.
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.
<?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name = "Suite1"> <test name = "test1"> <classes> <class name = "NewTestngClass" /> <class name = "OrderofTestExecutionInTestNG" /> </classes> </test> </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 ===============================================
- Related Articles
- How to run multiple test cases using TestNG Test Suite in Selenium?
- How to run test groups in TestNG?
- How to combine multiple groups to single Test in TestNG?
- How does TestNG invoke a test method using multiple threads?
- How to run TestNG from command line?
- How to get the name of a test method that was run in a TestNG teardown method?
- How will you run a prerequisite method and post condition method for\nevery test in TestNG?
- How to skip TestNG test at runtime?
- How to skip a particular test method in TestNG?
- How to disable an entire unit test in TestNG?
- How to set priority to the test cases in TestNG?
- How to retrieve all test methods name in TestNG suite?
- How test runner prioritize test classes for execution in Selenium?
- How to run Selenium WebDriver test cases in Chrome?
- How to overlook a particular test method from execution in TestNG?
