
TestNG is an open-source automated testing framework, where ‘NG’ of TestNG is Next Generation. It is similar to JUnit but designed to be better than JUnit, especially when testing integrated classes. With the help of simple annotations, grouping, sequencing & parametrization, TestNG overcomes most of the older system’s limitations and gives the developer the ability to write more versatile and efficient tests.
Jenkins is an open-source automation server that is widely used for continuous integration (CI) and continuous delivery (CD) processes. It provides a platform for automating the building, testing, and deployment of software projects. Jenkins is written in Java and is extendable through a vast ecosystem of plugins, making it highly flexible and customizable to fit various development and deployment needs.
In this blog, we will find out how to generate a TestNG report in Jenkins. This will be particularly useful if you are a automation tester and using Jenkins for CI/CD.
Steps
Step 1: Install Jenkins and TestNG plugins
Ensure that you have Jenkins installed and running. Also, make sure you have the TestNG plugin installed in Jenkins. If you haven’t installed it yet, go to “Manage Jenkins” > “Manage Plugins” > “Available” tab, and search for “TestNG” in the filter box. Install the TestNG plugin and restart Jenkins if prompted.


Step 2: Configure Jenkins job
Assuming you have a Java project with TestNG tests already set up, create or configure your Jenkins job to build and execute the TestNG tests. below are the steps you need to follow:
2.1 Create a new Jenkins job or configure an existing one by clicking on “New Item” on the Jenkins dashboard and selecting “Freestyle project” or “Pipeline” depending on your preference.

2.2 Configure your source code repository in the job to pull the latest code.
2.3 Set up your build triggers (e.g., “Build when a change is pushed to GitHub”).
2.4 In the “Build” section, add the necessary build steps to compile your Java project (e.g., “Invoke Gradle script” or “Invoke Maven” if using Gradle or Maven).
2.5 Add a build step to execute your TestNG tests. To do this, you can use the “Invoke top-level Maven targets” or “Execute shell” (for Gradle or custom scripts) build step and provide the command to run your TestNG tests. For Maven:
clean test
For custom scripts or other build tools, use the appropriate command to run your TestNG tests.
Step 3: Publish TestNG report To generate and publish the TestNG report, follow these steps:
3.1 After your TestNG tests are executed as part of the build, you need to generate the TestNG report in the XML format. TestNG generates the report by default.
3.2 In the Jenkins job configuration, add a post-build action to “Publish TestNG Results.”
3.3 In the “TestNG XML report pattern,” specify the path to the TestNG XML report file relative to your Jenkins workspace. The default path is usually “**/test-output/testng-results.xml” if you’re using the standard TestNG configuration.
3.4 Save the Jenkins job configuration.
Now that your Jenkins job is set up to build and execute the TestNG tests and publish the TestNG report, you can run the job by clicking on “Build Now” or wait for the build to be triggered based on the configured build triggers.
Step 4: Run the Jenkins job Now that your Jenkins job is set up to build and execute the TestNG tests and publish the TestNG report, you can run the job by clicking on “Build Now” or wait for the build to be triggered based on the configured build triggers.
After the build completes, Jenkins will generate the TestNG report and display the results. You can access the TestNG report from the build’s page by clicking on the “TestNG Results” link. The report will provide details about the test executions, including pass/fail status, test duration, and more.
