Open In App

How to generate TestNG HTML report for your tests.

Last Updated : 08 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

TestNG HTML report is an automatically generated summary of test execution results presented in a user-friendly HTML format. This report provides detailed insights into the execution of your tests, making it easy to analyze and debug your test results.,

Features:

  • Number of Tests Executed: Displays the total number of tests that were run, including those that passed, failed, or were skipped.
  • Test Case Details: Includes information such as the execution time for each test case and its result (pass/fail).
  • Stack Traces: If a test fails, the report includes stack traces, which help in debugging and understanding why a test failed.
  • Hierarchical View: The report shows a hierarchical view of the tests, including test suites, test classes, and individual test methods, helping you understand the structure of your tests.

Here are the steps to generate TestNG HTML Report:

Step 1: Create a Maven-based Java project in Eclipse to generate TestNG HTML reports.

Step 2: To set up TestNG in a Maven project, open your pom.xml file and add the following dependencies for TestNG and the Maven Surefire Plugin:

pom.xml

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.example</groupId>
  <artifactId>testng-reports-demo</artifactId>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    <!-- TestNG Dependency -->
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>7.10.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <!-- Maven Surefire Plugin for TestNG -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.3.1</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Save the pom.xml file. After saving, Eclipse will automatically download the necessary libraries and set up the project.

Step 3: Install TestNG in Eclipse, go to the Help menu, then select Eclipse Marketplace. In the search bar, type TestNG and click Go. Once TestNG appears, click Install and follow the prompts. After the installation is complete, restart Eclipse to setup.

TestNG-for-Eclipse
TestNG for Eclipse.

Step 4: Create a new test class, right-click on the src/test/java folder in your project and select New > Class. Name the class LoginTest.java and place it under the package com.example.tests. Then, create the class with the following code:

LoginTest.java

Java
package com.example.tests;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class LoginTest {
    private String appStatus;

    @BeforeMethod
    public void setUp() {
        appStatus = "Initialized"; // Simulate app setup
    }

    @Test
    public void testValidLogin() {
        String result = simulateLogin("[email protected]", "Pass123!");
        assertEquals(result, "Success", "Valid login should succeed");
    }

    @Test
    public void testInvalidLogin() {
        String result = simulateLogin("[email protected]", "WrongPass");
        assertEquals(result, "Failure", "Invalid login should fail");
    }

    @Test
    public void testEmptyEmail() {
        String result = simulateLogin("", "Pass123!");
        assertEquals(result, "Error: Email required", "Empty email should show error");
    }

    // Simulate login logic
    private String simulateLogin(String email, String password) {
        if (email.isEmpty()) {
            return "Error: Email required";
        }
        if (email.equals("[email protected]") && password.equals("Pass123!")) {
            return "Success";
        }
        return "Failure";
    }
}

Step 5: Create the testng.xml file, right-click on the project root directory and select New > File. Name the file testng.xml. Then, add the following dependencies to the testng.xml file:

testng.xml

XML
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="LoginTestSuite">
  <test name="LoginTests">
    <classes>
      <class name="com.example.tests.LoginTest"/>
    </classes>
  </test>
</suite>

Step 6: Run the TestNG suite, right-click on the testng.xml file and select Run As > TestNG Suite. This will trigger the execution of the tests defined in the testng.xml file, and the results will be displayed in the console and the TestNG report.

Output:

TestNG-Report-Index-html-file-output
TestNG Report Index html file output

Step 7. Double-click the index.html file to open it in a browser, or right-click the file and select Open With > Web Browser. This will display the TestNG report, showing details like the number of tests run, passed, failed, skipped, and the overall test execution time. It will also highlight any failed tests and provide insights into the errors.

Index-html-output-in-web-browser
Index HTML Report Output in Web Browser

With tools like TestNG, Maven, and Eclipse and customization options, TestNG HTML reports provide a powerful way to validate software efficiently.


Article Tags :

Explore