Backend Development 95 min read

Using BeautifulReport to Generate Custom TestNG HTML Reports for Java API Automation

This guide explains how to replace TestNG's default report with a custom BeautifulReport template in a Java Maven project, covering Maven dependency configuration, creating a TestReportListener, updating testng.xml, adding an HTML template, and viewing the generated report with detailed test results.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Using BeautifulReport to Generate Custom TestNG HTML Reports for Java API Automation

This article shows how to integrate BeautifulReport into a Java TestNG project to produce a more attractive HTML test report.

Step 1: Maven dependencies – add TestNG and ExtentReports to <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.14.3</version> </dependency> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>3.0.7</version> </dependency> .

Step 2: TestReportListener – create a listener class that implements IReporter . The class collects test results, formats them with Gson, and writes them into an HTML template located at src/test/resources/report/template.html . The full source is provided in the article.

Step 3: testng.xml configuration – register the listener in <listeners> <listener class-name="com.abcnull.listener.TestReportListener"/> </listeners> and define the test classes.

Step 4: HTML template – place a custom template.html (the article includes the full HTML skeleton) under src/test/resources/report . The template contains placeholders that the listener replaces with JSON data.

Step 5: View the report – after running the tests, the report is generated at target/test-output/report/自动化测试报告-YYYYMMDD,HH点mm分ss秒.html . Open the file in a browser to see summary statistics, a pie chart, and detailed test case information.

The article also provides a sample test class TestExtneter with passing, failing, and skipped tests, demonstrating how logs and exceptions appear in the report.

JavaMavenTestNGAPI testinghtml-reportBeautifulReport
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.