All Projects → adessoAG → junit-insights

adessoAG / junit-insights

Licence: MIT license
Extension for JUnit which provides insights for the runtime of contexts, classes and methods

Programming Languages

kotlin
9241 projects
Vue
7211 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to junit-insights

xunit-to-junit
This Extensible Stylesheet Language Transformations can transform a xUnit.net v2 XML test results file into a JUnit test results file.
Stars: ✭ 21 (-81.25%)
Mutual labels:  junit
justtestlah
Dynamic test framework for web and mobile applications
Stars: ✭ 43 (-61.61%)
Mutual labels:  junit
timber-junit-rule
A highly configurable JUnit Rule that outputs Timber logs to standard output
Stars: ✭ 42 (-62.5%)
Mutual labels:  junit
osgi-testsuite
The OSGi Test Suite runs all JUnit tests in a given list of bundles
Stars: ✭ 15 (-86.61%)
Mutual labels:  junit
jpa-unit
JUnit extension to test javax.persistence entities
Stars: ✭ 28 (-75%)
Mutual labels:  junit
kafka-junit
JUnit rule for spinning up a Kafka broker
Stars: ✭ 97 (-13.39%)
Mutual labels:  junit
zerocode-hello-world
Zerocode YAML and JSON based declarative steps hello world rest api testing example - soap, database
Stars: ✭ 18 (-83.93%)
Mutual labels:  junit
giulius-selenium-tests
A test harness that allows Selenium tests to be run using JUnit and test fixtures to be created and injected by a WebDriver-aware Guice
Stars: ✭ 12 (-89.29%)
Mutual labels:  junit
KDirtyAndroid
A dirty approach for truly client Android applications using Kotlin
Stars: ✭ 17 (-84.82%)
Mutual labels:  junit
testing-spring-boot-applications-masterclass
🍃 Everything You Need to Know About Testing Spring Boot Applications
Stars: ✭ 185 (+65.18%)
Mutual labels:  junit
j8spec
Library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine.
Stars: ✭ 45 (-59.82%)
Mutual labels:  junit
travis-ci-tutorial-java
Just to learn how to use travis-ci in a java project!
Stars: ✭ 38 (-66.07%)
Mutual labels:  junit
junit5-demo
Demos for JUnit 5
Stars: ✭ 46 (-58.93%)
Mutual labels:  junit
HiveRunner
An Open Source unit test framework for Hive queries based on JUnit 4 and 5
Stars: ✭ 244 (+117.86%)
Mutual labels:  junit
scalatest-junit-runner
JUnit 5 runner for Scalatest
Stars: ✭ 30 (-73.21%)
Mutual labels:  junit
springboot-rest-api-angularjs-https
REST API https with Spring Boot and Angular JS. Use MySQL, Hibernate and Spring Security.
Stars: ✭ 38 (-66.07%)
Mutual labels:  junit
junit4git
Junit Extensions for Test Impact Analysis
Stars: ✭ 40 (-64.29%)
Mutual labels:  junit
faketime
Fake currentTimeMillis() without class loader hacks
Stars: ✭ 100 (-10.71%)
Mutual labels:  junit
ginkgo4j
A Java BDD Testing Framework (based on RSpec and Ginkgo)
Stars: ✭ 25 (-77.68%)
Mutual labels:  junit
spring-jooq-flyway-testcontainers-junit5
🚀 Example project with configured Spring Boot, JooQ, TestContainers, MySQL container and JUnit5
Stars: ✭ 29 (-74.11%)
Mutual labels:  junit

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].