Skip to content Skip to navigation
Check Our New Demo Website!

Configuring ReportNG with TestNG for HTML Reports

ReportNG is a simple plug-in for the TestNG unit-testing framework to generate HTML reports as a replacement for the default TestNG HTML reports. You can also customize html report with the help of TestNG listeners.

To use ReportNG reports we need to follow the below three steps:

Step 1: Add the below Jars Files to your project.

reportng-1.1.4.jar
velocity-dep-1.4.jar
guice-3.0.jar

Please use the below links to download the jars.

Click here to Download ReportNG and Velocity jars. Click on downloads to download the jars. You just need to unzip and add to the project.

Click here to download Google Guice Jar. You need to unzip and add guice.jar once the download completes.

The structure should look like below:
ReportNG Jars

Step 2: The Most important step, to make sure reportNG reports, we need to disable the default TestNG Listeners.

It can be done by following the below steps:

1. Right Click on Properties
2. Click on TestNG
3. You will find an option as "Disable default listeners", check the checbox
4. Click on "Apply" button, it will show as message as "Project preferences are saved".
5. Now Click on "OK" button.

The screen should look like the below:

TestNG Properties

Step 3: We need to add the below two listeners to testng.xml file.

<listeners>
      <listener class-name="org.uncommons.reportng.HTMLReporter"/>
      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
  </listeners>

Finally testng.xml file should look as the below for the given example :

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1" >
<listeners>
      <listener class-name="org.uncommons.reportng.HTMLReporter"/>
      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
  </listeners>
  <test name="Regression Test Suite"   >
    <packages>
      <package name="packOne" />
      <package name="packTwo" />
   </packages>
 </test>
</suite>

The example code as follows:

Please add two packages as "packOne" and "packTwo" and a class for both the packages.

Package: PackOne
Class : demoOne

Here the first testcase will result in failure as i have used timeOut as 1000, to show you the report with both PASS and FAIL report.

package packOne;
import org.testng.annotations.Test;
public class demoOne {
	@Test(timeOut=1000)
	public void firstTestCase() throws InterruptedException
	{
		System.out.println("im in first test case from demoOne Class");
		Thread.sleep(1500);
	}
	@Test
	public void secondTestCase()
	{
		System.out.println("im in second test case from demoOne Class");
	}
}

Package : packTwo
Class : demoTwo

package packTwo;
import org.testng.annotations.Test;
public class demoTwo {
	@Test
	public void firstTestCase()
	{
		System.out.println("im in first test case from demoTwo Class");
	}
	@Test
	public void secondTestCase()
	{
		System.out.println("im in second test case from demoTwo Class");
	}
}

The below report is with the Default TestNG HTML Report.

TestNG Reports

Please execute the testcases/scripts to see the reports as below. After executing the testcases, Refresh the project folder to see the updated Reports. You will find a folder "html" and click on Index.html file to view the Report Generated By ReportNG

The below is the Overview Report generated after configuring the ReportNG with TestNG.

ReportNg Report Overview

The below is the Report generated after configuring the ReportNG with TestNG.

ReportNg Report

Test Frameworks: 

Comments

I came across one of pdfreport listener for testng. which as jfree chart also in the report. link is
https://github.com/uttesh/mavenrepos/tree/master/pdfreport

Thanks for providing good article.

Hi,
in Step 3: We need to add the below two listeners to testng.xml file.
I don't understand this step.
Do i have to create testing.xml file or chose the existing. If i had to create, where should i save it and how to call it.
Please help me on this. Thanks guys in advance.

You need add the testng.xml if that doesn't exists. You need to create it under the project folder (Not at any other place).

Please add those listeners to your testng.xml and it has also shown in the above example

I have followed the same as above steps mentioned but i am not getting the html folder generated anything else to done prior to this.. pls help...... thanks in advance

Please select the project folder and click on refresh. Then you should be able to see the folder 'test-out' in which you will have a html file.

Even after refreshing the project i cannot see the html folder getting created

Hi could you let me know hw u resolved the problem of not getting the html folder..i've followed the following steps as it is but i cant see my html folder even though i added the listners..please do help. Thanks in advance

Im also faced the same problem just do one thing , initially we disable the listners,right, dont do that uncheck that checkbox and after completion of execution referesh the project and u will get the html folder. try it works.

hi, thanks for the post. The index.html file is not emailable. i want to generate an emailable report that can be share among stack holders and senior personals. Can anyone share me the solution.
Thanks ...........

Pages

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.