• Stars
    star
    144
  • Rank 254,012 (Top 6 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extension for JUnit which provides insights for the runtime of contexts, classes and methods

Build Status codebeat badge

JUnit Insights

JUnit Insights is an extension for JUnit 5 (optionally in combination with the Spring framework), which

  1. measures the time for setup, execution and teardown for each test method in each test class
  2. (optional) measures how often Spring contexts were created and how long this takes
  3. creates a nice looking report that visualizes the data (see screenshot below)

Background: When building integration tests with Spring (e.g. with @SpringBootTest), sometimes a Spring application context has to be started and sometimes it doesn't. For the user of the test classes, it looks like some tests take a long time to execute, although the actual test runs fairly quickly. To make this behavior transparent, a report is created.

If you want to learn more about when a new Application Context is created, have a look at this article explaining the topic.

Usage

Activating the extension

First of all, you need to tell JUnit Insights that it should be activated via a system property.

Gradle:

test {
    systemProperty 'de.adesso.junitinsights.enabled', 'true'
}

Maven:

<plugins>
...
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
            <systemPropertyVariables>
                <de.adesso.junitinsights.enabled>true</de.adesso.junitinsights.enabled>
            </systemPropertyVariables>
        </configuration>
    </plugin>
...
</plugins>

Adding individual classes to the benchmark

Add @JUnitInsights to the test classes you want to benchmark. If you want to exclude methods from the benchmark, add @NoJUnitInsights to those. Be aware that ExtendsWith(SpringExtension::class) needs to be used as Runner-class.

Including all test classes

Alternatively, if you want to add the extension to all your test classes, you have to activate autodetection for JUnit 5 in your build file and activate JUnit Insights:

Gradle:

test {
    systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
}

Maven:

<plugins>
...
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
            <systemPropertyVariables>
                <de.adesso.junitinsights.enabled>true</de.adesso.junitinsights.enabled>
                <junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
            </systemPropertyVariables>
        </configuration>
    </plugin>
...
</plugins>

Further information can be found here

Changing the destination path for the reports

By default, created reports are stored in the build/reports directory. You can change this, by changing the following system property.

Gradle:

test {
    systemProperty 'de.adesso.junitinsights.reportpath', 'custom/report/directory/'
}

Maven:

<plugins>
...
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
            <systemPropertyVariables>
                <de.adesso.junitinsights.enabled>true</de.adesso.junitinsights.enabled>
                <junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
                <de.adesso.junitinsights.reportpath>reports/</de.adesso.junitinsights.reportpath>
            </systemPropertyVariables>
        </configuration>
    </plugin>
...
</plugins>

Dependency

For your convenience, JUnit Insights is available as a SNAPSHOT version from oss.jfrog.org. Just add the necessary repository and the dependency to your build file.

Gradle:

repositories {
    maven {
        url  "https://oss.jfrog.org/artifactory/oss-snapshot-local"
    }
}

dependencies {
    testCompile ('de.adesso:junit-insights:1.1.0-SNAPSHOT')
}

Maven:

<repositories>
    <repository>
        <id>oss-snapshot-local</id>
        <url>https://oss.jfrog.org/artifactory/oss-snapshot-local</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>de.adesso</groupId>
        <artifactId>junit-insights</artifactId>
        <version>1.1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

For local development

If you want to test a local version of this project in a different project than the tester/, build the jar and include it in your project like so:

Gradle:

dependencies {
    testCompile files('../junit-insights/library/build/libs/junit-insights-1.1.0.jar')
}

Maven:

<dependency>
    <groupId>de.adesso</groupId>
    <artifactId>junit-insights</artifactId>
    <version>1.1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/../junit-insights/library/build/libs/junit-insights-1.1.0.jar</systemPath>
</dependency>

How time is measured

The extension captures certain events in during the test plan execution to measure the time for each phase. Specifically the timestamps provided by the JUnit Jupiter extension API as well as the Spring ContextRefreshedEvent are captured. The following diagram gives an overview of the order of the events on the left and the time intervals that are captured on the right.

Overview of the captured timestamps

To further explain the meaning of the timestamps, following is an extract from the help dialog on the top right of the report site.

The Overview chart breaks down the total test time into the following components:

  • Spring: startup time for all Spring application contexts
  • Preparation: sum of all time that passed before the BeforeAll and BeforeEach callbacks
  • Execution: sum of all time that passed between the BeforeEach and AfterEach callbacks
  • Tear-Down: like preparation but after the execution

The list down below shows an overview of the individual tested classes and the time spent on different tasks:

  • Spring: startup time of the possibly created Spring application context
  • Before All: tasks executed before any of the test methods are executed
  • Before: sum of the time used before each individual test method
  • Exec: sum of the execution time of all test methods
  • After: like before but after the execution
  • After All: like before all but after the execution

You can also expand the test classes and get the information about Before, Execution and After for the individual test methods.

Troubleshooting

If you get an error complaining about a missing JUnit platform launcher, for example

java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener

you need to add the dependency for the appropriate package.

If you have any other issues, feel free to open an issue in our issue tracker.

Screenshot

Screenshot 1

More Repositories

1

wicked-charts

Beautiful and interactive javascript charts for Java-based web applications.
JavaScript
89
star
2

coderadar

Continuous code analysis server.
Java
60
star
3

budgeteer

Simple Project Budget Monitoring via Web Browser
Java
31
star
4

Seed-Test

Low Code UI-Testing Platform with Selenium and Cucumber
TypeScript
25
star
5

devblog

adesso Developer Blog
CSS
25
star
6

anki-drive-java

A Java port of the Anki Drive SDK
Java
17
star
7

kong-plugin-soap2rest

A plugin for the Kong Microservice API Gateway to redirect a SOAP request to a REST API and convert the JSON Response to SOAP response.
Lua
14
star
8

wicked-forms

Create dynamic web forms with Java web frameworks.
Java
14
star
9

BrainySnake

BrainySnake - Program your AI and see who's better!
Java
11
star
10

JenkinsHue

An application to show the state of multiple Jenkins jobs on Philips Hue lamps
Java
11
star
11

ControllerVsMinimalApi

This is a sample .NET Core Web API project that demonstrates various architectural patterns and best practices for building scalable and maintainable applications. This project is intended to serve as a learning resource and a starting point for building real-world .NET Core applications.
C#
8
star
12

project-board

A web-based bulletin board for open positions in projects.
Java
7
star
13

softauthn

WebAuthn authenticator emulation in Java
Java
5
star
14

eureka-prometheus-bridge

Bridge for Eureka and Prometheus written in Kotlin
Kotlin
5
star
15

jekyll2cms

Tool for exporting github repo to a CMS
Java
3
star
16

expressive-testing-demo

Expressive Testing Demo
Java
3
star
17

anki-battle-showcase

Java
3
star
18

WorkshopEvonik

Jupyter Notebook
2
star
19

Git-Intel-Spring

Git-Intel: Every organisation, Every Detail.
Java
2
star
20

Git-Intel-UI

A new UI for the GitStalker Library using bootstrap.
TypeScript
2
star
21

adessoKicker

Application that records table football matches and ranks players based on their performance
Java
2
star
22

node-api-prebuilts

A CLI and library to manage, locate and load prebuilt node addons targetting Node-API.
TypeScript
2
star
23

facenality-model

Deep learning model for predicting personality traits based on facial features.
Python
2
star
24

LearnDistributedEcom

A C# sample project demonstrating the intricacies of distributed systems in an e-commerce setting, using microservices, MassTransit, and integrated telemetry with Jaeger and Application Insights.
C#
1
star
25

BankingShowCase

TypeScript
1
star
26

DDD-Template

That is an example of the implementation of domain driven design with onion architecture
C#
1
star
27

css-for-backend-devs-aufgaben

Aufgaben für CSS for backend developers Workshop
HTML
1
star
28

adesso-indoor-navigator

JavaScript
1
star
29

squadmap

Java
1
star
30

git-intel-docker

The Docker Compose file for the Git-Intel Project
1
star
31

tech-radar

JavaScript
1
star
32

generator-ssjs

JavaScript
1
star
33

ssjs-webpack

SSJS + Webpack Boilerplate
JavaScript
1
star