TestNG Reporting in HTML Format

In this blospost, we will learn how to generate HTML Reports for the execution of TestNG Suite.

As we already know that, JUnit does not have inbuilt Reporting Capabilities, but TestNG has a powerful way of generating HTML Reports of our test execution.

Let us go through the working example of executing a TestNG Suite and generating HTML report of the execution.

Step 1: Create one TestNG class file, and name it as TestClass1. java.

package com;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestClass1 {

public void beforeSuite() {
System.out.println(“Inside Before Suite Method.”);

public void beforeClass() {
System.out.println(“Inside Before Class of TestClass1.”);

public void beforeTest() {
System.out.println(“Inside Before Test Method of TestClass1.”);

public void beforeMethod1() {
System.out.println(“Inside Before Method 1 of TestClass1.”);

public void beforeMethod2() {
System.out.println(“Inside Before Method 2 of TestClass1.”);

public void testMethod1() {
System.out.println(“Inside Test Method 1 of TestClass1.”);

public void testMethod2() {
System.out.println(“Inside Test Method 2 of TestClass1.”);

public void afterTest() {
System.out.println(“Inside After Test Method of TestClass1.”);

public void afterMethod1() {
System.out.println(“Inside After Method 1 of TestClass1.”);

public void afterMethod2() {
System.out.println(“Inside After Method 2 of TestClass1.”);

public void afterClass() {
System.out.println(“Inside After Class Method of TestClass1.”);

public void afterSuite() {
System.out.println(“Inside After Suite Method.”);

Step 2: Create a TestNG.xml

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>

<suite name=”Suite”>
<test name=”TestSuiteDemo”>
<class name=”com.TestClass1″ />

Step 3. Run the TestNG suite, Right Click on TestNG.xml -> Run As -> TestNG Suite. When the execution is completed, a new folder with the name test-output will be created under the project.


Open index.html, in your preferred web browser, and you will be able to see the detailed HTML Report of TestNG suite execution.


That is it from this blogpost, hope it works for you!

Cheers 🙂