Tutorial

JUnit HTML Report

Published on August 4, 2022
author

Pankaj

JUnit HTML Report

When we configure maven-surefire-plugin to run our JUnit tests, it generates surefire-reports directory. This directory contains a txt file and an XML file for every test class. However, reading these files is not easy and it’s also not easily explainable to a non-techie person.

JUnit HTML Report

We can use maven-surefire-report-plugin plugin to generate HTML based reports for our JUnit tests. This report can be exported and shared with the team. It’s also an easy way to understand how your tests went through, especially when you integrate them with CI tools like Jenkins. There are two steps to generate JUnit HTML report from our maven project.

  1. Add maven-surefire-report-plugin to pom.xml reporting element.

    <reporting>
    	<plugins>
    		<plugin>
    			<groupId>org.apache.maven.plugins</groupId>
    			<artifactId>maven-surefire-report-plugin</artifactId>
    			<version>2.22.0</version>
    		</plugin>
    	</plugins>
    </reporting>
    
  2. Run mvn site command from the terminal. It will generate HTML reports in target/site directory.

Open the surefire-report.html file in the browser. You will get an output like below image, it’s from my JUnit Examples project. JUnit HTML Reports using Maven Surefire Report Plugin Some of the useful information we get from JUnit HTML report are:

  • Test Packages and Classes
  • Test Methods names from specific classes
  • Failure tests or skipped tests with reason
  • Execution time taken by each method

Summary

TestNG supports built-in HTML report generation whereas JUnit HTML reports are generated by maven surefire plugin and we have to execute an additional command for it. However, JUnit HTML reports look much better when compared to TestNG HTML reports.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Pankaj

author

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
August 31, 2021

I didn’t see any html reports generated. I used the https://raw.githubusercontent.com/journaldev/journaldev/master/JUnit5-Example/pom.xml wondering what is missing :(

- nags

    JournalDev
    DigitalOcean Employee
    DigitalOcean Employee badge
    July 7, 2021

    In case of any failure, site goal will not run, this method is unreliable

    - Amado Saladino

      JournalDev
      DigitalOcean Employee
      DigitalOcean Employee badge
      January 4, 2020

      Good article but we need to add the following lines in the pom.xml in order to avoid some compilation problems due to the obsolete pugin site: org.apache.maven.plugins maven-site-plugin 3.7.1 org.apache.maven.plugins maven-project-info-reports-plugin 3.0.0

      - Karim Djaafar

        Try DigitalOcean for free

        Click below to sign up and get $200 of credit to try our products over 60 days!

        Sign up

        Join the Tech Talk
        Success! Thank you! Please check your email for further details.

        Please complete your information!

        Become a contributor for community

        Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

        DigitalOcean Documentation

        Full documentation for every DigitalOcean product.

        Resources for startups and SMBs

        The Wave has everything you need to know about building a business, from raising funding to marketing your product.

        Get our newsletter

        Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

        New accounts only. By submitting your email you agree to our Privacy Policy

        The developer cloud

        Scale up as you grow — whether you're running one virtual machine or ten thousand.

        Get started for free

        Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

        *This promotional offer applies to new accounts only.