How to call testng.xml file from pom.xml in Maven?
Last Updated :
23 Jul, 2025
Maven is a tool that is widely used for automation whenever developers work on Java projects. apart from the Java language, the Maven software supports other projects that are written in C#, Ruby, etc. The Maven project is controlled and hosted by the famous Apache software foundation.
What is a testng.xml file?
Testng.xml is a popular file that is used in the maven software or project, it is provided by the TestNG testing framework and it is used to define and control the execution of the tests. the testng.xml file is used to specify the test classes as well as the test methods to run and also provides other settings for the testing.
What is a pom.xml file?
The pom.xml file stands for the project object model and it is a file that is used for the configuration of the project, it is used for defining the project's structure and dependencies, as well as other configurations for the project.
How to call the testng.xml file from pom.xml in Maven?
Following are the steps required for calling the testng.xml file from pom.xml:
Step 1: Create java file:
The first step is to create a testng.xml file for the original java file, for this, we will need to have a java file.
Note: If you currently do not have a java file then you can use the following java file, it is not mandatory to have the file name as testng.xml
Java
package mynewpackage;
import org.testng.annotations.Test;
public class MyCases {
@Test
public void testOne() {
System.out.println("this is my first test");
}
@Test
public void testTwo() {
System.out.println("this is my second test");
}
@Test
public void testThree() {
System.out.println("this is my third test");
}
@Test
public void testFour() {
System.out.println("this is my fourth test");
}
@Test
public void testFive() {
System.out.println("this is my fifth test");
}
@Test
public void testSix() {
System.out.println("this is my sixth test");
}
}
Step 2: Create testng.xml file:
After creating or copying code for the java file, we will have to create the testng.xml file, for this simply right click on the java file and go to TestNG > Convert to TestNG and click on finish. it will automatically create the testng.xml file for us.
Create testng.xml file.If you are using the above java code then the following testng.xml file will be generated (it will differ if the java code is different):
XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="mynewpackage.MyCases"/>
</classes>
</test> <!--Test -->
</suite> <!-- Suite -->
Step 3: Run pom.xml file:
Next step is to run the pom.xml file, unlike the testng.xml file the pom.xml file will be already present inside the maven project, as you can see in the image below:
Run pom.xml file.pom.xml file will contain the following code in it:
XML
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ats</groupId>
<artifactId>RuntestngXmlFromPOM</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>RuntestngXmlFromPOM</name>
<url>http://maven.apache.org</url>
<properties>
<project build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testngsecond.xml</suiteXmlFile>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
Step 4: Call testng.xml from pom.xml:
Now the next step is to run the testng.xml file using the pom.xml for this right click on the pom.xml file and click on the maven run option.
Call testng.xml from pom.xmlStep 5: Test output:
Once you click on the maven run option, it will display a small pop up window in which the output will be displayed, it will be similar to the output below:
Test output.This means that we have successfully called the testng.xml file using the pom.xml file in the maven project.
Conclusion
This is a method which allows the maven to execute the various tests which are defined within the testng.xml file, this setup uses the TestNG and it integrates it with the maven software which enables the test execution to happen automatically during the build process and also helps us in making sure that the test management is more efficient.
Similar Reads
Software Testing Tutorial Software testing is an important part of the software development lifecycle that involves verifying and validating whether a software application works as expected. It ensures reliable, correct, secure, and high-performing software across web, mobile applications, cloud, and CI/CD pipelines in DevOp
10 min read
What is Software Testing? Software testing is an important process in the Software Development Lifecycle(SDLC). It involves verifying and validating that a Software Application is free of bugs, meets the technical requirements set by its Design and Development, and satisfies user requirements efficiently and effectively.Here
11 min read
Principles of Software testing - Software Testing Software testing is an important aspect of software development, ensuring that applications function correctly and meet user expectations. From test planning to execution, analysis and understanding these principles help testers in creating a more structured and focused approach to software testing,
3 min read
Software Development Life Cycle (SDLC) Software Development Life Cycle (SDLC) is a structured process that is used to design, develop, and test high-quality software. SDLC, or software development life cycle, is a methodology that defines the entire procedure of software development step-by-step. The goal of the SDLC life cycle model is
8 min read
Software Testing Life Cycle (STLC) The Software Testing Life Cycle (STLC) is a process that verifies whether the Software Quality meets the expectations or not. STLC is an important process that provides a simple approach to testing through the step-by-step process, which we are discussing here. Software Testing Life Cycle (STLC) is
7 min read
Types of Software Testing Software testing is a important aspect of software development life-cycle that ensures a product works correctly, meets user expectations, and is free of bugs. There are different types of software testing, each designed to validate specific aspects of an application, such as functionality, performa
15+ min read
Levels of Software Testing Software Testing is an important part of the Software Development Life Cycle which is help to verify the product is working as expected or not. In SDLC, we used different levels of testing to find bugs and errors. Here we are learning those Levels of Testing in detail.Table of ContentWhat Are the Le
4 min read
Test Maturity Model - Software Testing The Test Maturity Model (TMM) in software testing is a framework for assessing the software testing process to improve it. It is based on the Capability Maturity Model(CMM). It was first produced by the Illinois Institute of Technology to assess the maturity of the test processes and to provide targ
8 min read
SDLC MODELS
TYPES OF TESTING