Home » Core Java » junit » JUnit Report Example

About Alvin Reyes

Alvin has an Information Technology Degree from Mapua Institute of Technology. During his studies, he was already heavily involved in a number of small to large projects where he primarily contributes by doing programming, analysis design. After graduating, he continued to do side projects on Mobile, Desktop and Web Applications.

JUnit Report Example

1. Introduction

In all the test cases of an application, there is always a way to create a report of it one way or the other. JUnit is not an exception to this and there’s a ton of ways to create reports from it. It can even be incorporated to the maven site and have it part of the overall java tech documentations of a Java Application.

One of the most widely used JUnit reporting plugin is the surefire and in this post, I’ll be showcasing how it can be used on your JUnit test cases.

2. The Surefire reporting  plugin

The Surefire Report Plugin parses the generated TEST-*.xml files under ${basedir}/target/surefire-reports and renders them using DOXIA, which creates the web interface version of the test results. It also allows generating reports in HTML format which will be the focus of our samples in this post. You can check the surefire plugin from here.

To configure your project to have surefire plugin, just include the following reporting plugin on the pom.xml of your maven project.



This will allow your project to call the surefire plugin goals to generate the HTML report.

3. Source

Let’s try creating a JUnit Test case and run the surefire report generation.


package com.areyes1.junitreport.service;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
public class JUnitReportServiceExampleTest {

	private JUnitReportServiceExample junitAssertEqualsServiceSample;
	private ServiceObject serviceObject;
	public void setData() {
		serviceObject = new ServiceObject();
		junitAssertEqualsServiceSample = new JUnitReportServiceExample();

	public void testAssertEqualsFalse() {
		//	processed the item
		ServiceObject newServiceObject = new ServiceObject();
	public void testAssertEquals() {

	public void testAssertEqualsWithMessage() {
				"Same Object",
	public void testAssertEqualsFalseWithMessage() {
		ServiceObject newServiceObject = new ServiceObject();
				"Not the Same Object",


We create several test cases here that will succeed and fail. We then run the following command to generate the report.

mvn clean install test surefire-report:report

The report will be generated under the target folder of your maven project.

Figure 1.0 Surefire HTML and XML under the target folder

Figure 1.0 Surefire HTML and XML under the target folder

4. Reports

Here is an example of a report generated by the plugin.

Figure 2.0 JUnit HTML report

Figure 2.0 JUnit HTML report

It gives you the number of succeeded and failed test cases as well as the percentage covered (coverage) of your test cases. It’s a pretty neat reporting for projects that are keen to their quality of testing per build cycles. I see this as an extremely great feature for any Java application as the success of the test cases is directly proportional to the quality of the functionality of the application.

5. Download the Eclipse project

This was an example about JUnit Report.

You can download the full source code of this example here : junit-report-example

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area


Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments