Contents

Create HTML report with JUnit

Written by: David Vlijmincx

Introduction

In this quick tutorial, I am going to show you how to create an HTML report of your JUnit tests using Maven.

Maven

You can use the maven-surefire-report-plugin plugin to help you create an HTML report of your tests. You need to add the following plugin to your pom.xml.

1
2
3
4
5
6
7
8
9
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>3.0.0</version>
        </plugin>
    </plugins>
</reporting>

To generate the report use the following command.

1
mvn site

When you added the plugin and ran the command you can find the JUnit html report inside the target/site directory.

Gradle

The Gradle Test task already creates an HTML report. You can find it in the directory target/report/tests/.

Conclusion

This quick tutorial showed you how to generate an HTML report using Maven and JUnit. You only need to add a single plugin to be able to generate it. If you are using Gradle you only have to run the Test task which will generate a HTML report for you.