EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials JUnit Tutorial JUnit Report
Secondary Sidebar
JUnit Tutorial
  • Junit
    • JUnit 5 Assert
    • JUnit RunWith
    • JUnit AssertThat
    • JUnit Report
    • JUnit BeforeClass
    • JUnit Framework
    • JUnit Data Provider
    • JUnit Runner
    • JUnit 5 Parameterized Tests
    • JUnit BeforeAll
    • JUnit Private Methods
    • JUnit Integration Test
    • JUnit Maven Dependency
    • JUnit Annotations?
    • JUnit Testing
    • JUnit Test Order
    • JUnit 5 RunWith
    • JUnit 4 Maven
    • JUnit Jar
    • JUnit assertEquals
    • JUnit 5 Parameterized Test
    • JUnit Dependency
    • JUnit Fail
    • JUnit Disable Test
    • JUnit Assert
    • JUnit in Maven
    • JUnit 5 Gradle
    • JUnit XML
    • JUnit XML Format
    • JUnit Eclipse
    • JUnit Test Suite
    • JUnit Parameterized Test
    • JUnit assert exception
    • JUnit Code Coverage
    • JUnit Jupiter
    • JUnit Rule
    • JUnit version
    • Junit Interview Questions

JUnit Report

Introduction to JUnit Report

Junit report is generated in the application using the framework of junit, as we know that junit is used in several applications as a framework of the test. By default, the junit framework generates the simple report of xml files for the test execution. This type of xml file generates custom reports per the junit testing requirement.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,950 ratings)

We can also generate the reports using xml files and the ant tool for generating the report. Ant is a utility task, it will take xml files of junit as input, and then it will generate the html report. TestNG, by default, creates the xml report of junit for the test execution. So we can use an xml report file as input for generating the report of junit. Junit framework will help us to validate the methods in functionality. But in other cases, we need to see our report in test cases.

JUnit Report

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Create JUnit Report Class

  • Developing reports maven is essential in making the report of text, XML, and html.
  • All the junit test cases with all details will print into the reports. We can generate it in different ways like TestNG, ant, and many types of libraries. We can also develop it by using maven.
  • To create a class, we need to use the maven surefire report plugin for generating the html based report, which was used for junit tests. Then, we can export this report in our test of junit and share the same with our team. Using the junit reports class also makes it easy to understand how our tests go, specifically when integrating them into the CI tools.
  • The below example shows the creation of a junit reports class as follows. In the below example, we are defining the class name as junitreport. After creating the class, we used the @Test annotation to write the test cases. Then, we use the user-defined method to create the junit reports class. After using the @Test annotation, we use assert annotation using true and false conditions.
  • We use the assert condition three times to define the junit report class. It is essential and valuable to create junit reports.
  • In the below example, we have defined three test methods to create a junit report class as follows.

Code:

public class JunitReport {
@Test
public void test1 () {
Assert.assertTrue (true);
}
@Test
public void test2 () {
Assert.assertTrue (false);
}
@Test
public void test3 () {
Assert.assertTrue (true);
}
}

Output:

JUnit Report 1

JUnit Report 2

JUnit Report Project Setup

We can set up a junit project by using multiple ways. We set up the project using the spring tool suite in the example below. At the time of setup of the project, we are using the maven plugin as follows.

At the time of creating the project setup of junit reports, we are also adding the dependency of junit.

We are using the below technologies at the time of the new setup of the junit report project as follows.

Java – It is the primary language of coding.
Spring tool suite – It is IDE for project development.
Maven – This is used for generating test cases and reports and is a dependency management tool.
Junit 4.12 – It’s a testing framework.

The below steps show to set up the project as follows.

We are creating the project name as JunitReport.

In this step, we create the project template of junit reports in spring boot. We provide project group names as com. Examples are artifact names such as JunitReport, project names such as JunitReport, and selected java versions as 11. We are defining the version of spring boot as 2.6.7.

Group – com.example Artifact name – JunitReport
Name – JunitReport Spring boot – 2.6.7
Project – Maven Java – 11
Package name – com.example. JunitReport
Project Description – Project for JunitReport

JUnit Report 3

In this step, we extract the downloaded project and open the same by using the spring tool suite.

extracting the downloaded project

In this step, we check all the project structure and its files. Also, we are checking whether that pom.xml file is created or not. If this file is not created, we need to create the same manually. However, this file is created in the below example, so we do not need to create it manually.

checking all the project structure

In this step, we add the junit dependency in the junit report project. We are adding junit dependency as follows.

Code:

<dependencies>
<dependency>
<groupId> org.junit.jupiter </groupId>
<artifactId> junit-jupiter-engine </artifactId>
<version> 5.3.1 </version>
<scope> junit- report </scope>
</dependency>
<dependency>
<groupId> junit </groupId>
<artifactId> junit </artifactId>
<version> 4.12 </version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source> 1.8 </maven.compiler.source>
<maven.compiler.target> 1.8 </maven.compiler.target>
</properties>
<reporting>
<plugins>
<plugin>
<groupId> org.apache.maven.plugins </groupId>
<artifactId> maven-surefire-report-plugin </artifactId>
<version> 2.19.1 </version>
</plugin>
</plugins>
</reporting>

Output:

JUnit Report 6

Example of JUnit Report

In the below example, we are creating the class name JunitReport_Class to define the example of junit reports.

After creating the class, we used the @Test annotation to write the test cases. We are using the user-defined method to create the junit report class. After using the @Test annotation, we used assert annotation using true and false conditions.

Code:

public class JunitReport_Class {
@Test
public void class_test1 () {
Assert.assertTrue (true);
}
@Test
public void class_test2 () {
Assert.assertTrue (false);
}
@Test
public void class_test3 () {
Assert.assertTrue (true);
}
}

Output:

JUnit Report 7

After creating the above class in this step, we create the sample html file as follows.

Code:

<?xml version = "1.0" encoding = "UTF-8"?>
<suite name = "junit Suite">
<test name = "junit report">
<classes>
<class name = "JunitReport" />
</classes>
</test>
</suite>

Output:

sample html file

After creating a sample xml file, we run our project using the running configuration. Below is the method to run the junit report project as follows.

running our project by using running configuration

JUnit Report 10

JUnit Report 11

Conclusion

We can generate the reports using xml files; also, we can use the ant tool for generating the report. It is generated in the application by using the framework of junit, as we know that junit is the framework that was used in several applications as a framework for the test.

Recommended Articles

This is a guide to JUnit Report. Here we discuss the introduction and create a JUnit report class, project setup, and example. You may also have a look at the following articles to learn more –

  1. JUnit Code Coverage
  2. JUnit assertEquals
  3. JUnit Jupiter
  4. JUnit 5 Maven Dependency
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more