TestNG HTML and XML Reports


TestNG comes with certain predefined listeners as part of the library. These listeners are by default added to any test execution and generate different HTML and XML reports for any test execution. The report is generated by default under the folder named testoutput and can be changed to any other folder by configuring it. These reports consist of certain HTML and XML reports that are TestNG specific.

Create Test Case Class

Create a java class, say, SampleTest.java in C:\ > TestNG_WORKSPACE.

import org.testng.Assert;
import org.testng.annotations.Test;

public class SampleTest {
    public void testMethodOne(){
    public void testMethodTwo(){
        public void testMethodThree(){

The preceding test class contains three test methods out of which testMethodOne and testMethodThree will pass when executed, whereas testMethodTwo is made to fail by passing a false Boolean value to the Assert.assertTrue method, which is used for truth conditions in the tests.

Create testng.xml

Create testng.xml in C:\ > TestNG_WORKSPACE to execute test case(s).

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Simple HTML-XML Suite">
  <test name="Simple HTML-XML test">
      <class name="SampleTest" />

Compile the SampleTest class using javac.

C:\TestNG_WORKSPACE>javac SampleTest.java

Now, run the testng.xml.

C:\TestNG_WORKSPACE>java -cp "C:\TestNG_WORKSPACE" org.testng.TestNG testng.xml

Verify the output.

   Simple HTML-XML Suite
   Total tests run: 3, Failures: 1, Skips: 1

Now, go to the C:\TestNG_WORKSPACE\test-output folder. Open the index.html on your default web browser. You will see the following HTML report:

HTML Report

Now, open the file C:\TestNG_WORKSPACE\test-output\testing-results.xml in the default XML editor on your system, and you will see the following content in the XML file:

XML Report

TestNG, by default, generates multiple reports as part of its test execution. These reports mainly include TestNG HTML report, TestNG emailable report, TestNG report XML, and JUnit report XML files. These files can be found under the output report folder (in this case, test-output). This default report generation can be disabled while running the tests by setting the value of the property useDefaultListeners to false. This property can be set while using build tools like Ant or Maven.