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.
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.
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.
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>
mvn site command from the terminal. It will generate HTML reports in
surefire-report.html file in the browser. You will get an output like below image, it’s from my JUnit Examples project. Some of the useful information we get from JUnit HTML report are:
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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up now
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 :(
In case of any failure, site goal will not run, this method is unreliable
- Amado Saladino
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