{"id":23201266,"url":"https://github.com/adessose/junit-insights","last_synced_at":"2025-08-18T23:33:14.883Z","repository":{"id":37703621,"uuid":"123940253","full_name":"adessoSE/junit-insights","owner":"adessoSE","description":"Extension for JUnit which provides insights for the runtime of contexts, classes and methods","archived":false,"fork":false,"pushed_at":"2023-03-04T02:54:52.000Z","size":2503,"stargazers_count":147,"open_issues_count":20,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-17T22:38:45.127Z","etag":null,"topics":["gradle","junit","junit-extension","kotlin","spring","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adessoSE.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-03-05T15:34:40.000Z","updated_at":"2024-11-13T14:23:52.000Z","dependencies_parsed_at":"2023-10-20T16:20:54.490Z","dependency_job_id":null,"html_url":"https://github.com/adessoSE/junit-insights","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adessoSE%2Fjunit-insights","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adessoSE%2Fjunit-insights/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adessoSE%2Fjunit-insights/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adessoSE%2Fjunit-insights/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adessoSE","download_url":"https://codeload.github.com/adessoSE/junit-insights/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230292736,"owners_count":18203650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle","junit","junit-extension","kotlin","spring","spring-boot"],"created_at":"2024-12-18T15:14:43.632Z","updated_at":"2024-12-18T15:14:44.314Z","avatar_url":"https://github.com/adessoSE.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://www.travis-ci.com/adessoAG/junit-insights.svg?branch=master)](https://travis-ci.org/adessoAG/junit-insights)\n[![codebeat badge](https://codebeat.co/badges/bac44e06-3560-4c28-814c-b5495bfa3c28)](https://codebeat.co/projects/github-com-adessoag-junit-insights-master)\n# JUnit Insights\nJUnit Insights is an extension for JUnit 5 (optionally in combination with the Spring framework), which\n1. measures the time for setup, execution and teardown for each test method in each test class\n2. (optional) measures how often Spring contexts were created and how long this takes\n3. creates a nice looking report that visualizes the data (see screenshot below)\n\n**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.\nFor the user of the test classes, it looks like some tests take a long time to execute, although the actual test runs fairly quickly.\nTo make this behavior transparent, a report is created.\n\nIf you want to learn more about when a new Application Context is created, have a look at [this article](https://www.adesso.de/de/news/blog/identify-bottlenecks-in-your-spring-tests-with-junit-insights.jsp) explaining the topic.\n\n# Usage\n\n## Activating the extension\n\nFirst of all, you need to tell JUnit Insights that it should be activated via a system property.\n\nGradle:\n```gradle\ntest {\n    systemProperty 'de.adesso.junitinsights.enabled', 'true'\n}\n```\n\nMaven:\n```xml\n\u003cplugins\u003e\n...\n    \u003cplugin\u003e\n        \u003cartifactId\u003emaven-surefire-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e2.22.0\u003c/version\u003e\n        \u003cconfiguration\u003e\n            \u003csystemPropertyVariables\u003e\n                \u003cde.adesso.junitinsights.enabled\u003etrue\u003c/de.adesso.junitinsights.enabled\u003e\n            \u003c/systemPropertyVariables\u003e\n        \u003c/configuration\u003e\n    \u003c/plugin\u003e\n...\n\u003c/plugins\u003e\n```\n\n## Adding individual classes to the benchmark\n\nAdd `@JUnitInsights` to the test classes you want to benchmark.\nIf you want to exclude methods from the benchmark, add `@NoJUnitInsights` to those.\nBe aware that `ExtendsWith(SpringExtension::class)` needs to be used as Runner-class.\n\n## Including all test classes\n\nAlternatively, 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:\n\nGradle:\n```gradle\ntest {\n    systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'\n}\n```\n\nMaven:\n```xml\n\u003cplugins\u003e\n...\n    \u003cplugin\u003e\n        \u003cartifactId\u003emaven-surefire-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e2.22.0\u003c/version\u003e\n        \u003cconfiguration\u003e\n            \u003csystemPropertyVariables\u003e\n                \u003cde.adesso.junitinsights.enabled\u003etrue\u003c/de.adesso.junitinsights.enabled\u003e\n                \u003cjunit.jupiter.extensions.autodetection.enabled\u003etrue\u003c/junit.jupiter.extensions.autodetection.enabled\u003e\n            \u003c/systemPropertyVariables\u003e\n        \u003c/configuration\u003e\n    \u003c/plugin\u003e\n...\n\u003c/plugins\u003e\n```\n\nFurther information can be found [here](https://junit.org/junit5/docs/current/user-guide/#extensions-registration-automatic)\n\n## Changing the destination path for the reports\n\nBy default, created reports are stored in the `build/reports` directory. You can change this, by changing the following system property.\n\nGradle:\n```gradle\ntest {\n    systemProperty 'de.adesso.junitinsights.reportpath', 'custom/report/directory/'\n}\n```\nMaven:\n```xml\n\u003cplugins\u003e\n...\n    \u003cplugin\u003e\n        \u003cartifactId\u003emaven-surefire-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e2.22.0\u003c/version\u003e\n        \u003cconfiguration\u003e\n            \u003csystemPropertyVariables\u003e\n                \u003cde.adesso.junitinsights.enabled\u003etrue\u003c/de.adesso.junitinsights.enabled\u003e\n                \u003cjunit.jupiter.extensions.autodetection.enabled\u003etrue\u003c/junit.jupiter.extensions.autodetection.enabled\u003e\n                \u003cde.adesso.junitinsights.reportpath\u003ereports/\u003c/de.adesso.junitinsights.reportpath\u003e\n            \u003c/systemPropertyVariables\u003e\n        \u003c/configuration\u003e\n    \u003c/plugin\u003e\n...\n\u003c/plugins\u003e\n```\n\n# Dependency\n\nFor your convenience, JUnit Insights is available as a SNAPSHOT version from [oss.jfrog.org](https://oss.jfrog.org/webapp/#/artifacts/browse/tree/General/oss-snapshot-local/de/adesso/junit-insights). Just add the necessary repository and the dependency to your build file.\n\nGradle:\n\n```gradle\nrepositories {\n    maven {\n        url  \"https://oss.jfrog.org/artifactory/oss-snapshot-local\"\n    }\n}\n\ndependencies {\n    testCompile ('de.adesso:junit-insights:1.1.0-SNAPSHOT')\n}\n```\n\nMaven:\n\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003eoss-snapshot-local\u003c/id\u003e\n        \u003curl\u003ehttps://oss.jfrog.org/artifactory/oss-snapshot-local\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ede.adesso\u003c/groupId\u003e\n        \u003cartifactId\u003ejunit-insights\u003c/artifactId\u003e\n        \u003cversion\u003e1.1.0-SNAPSHOT\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n## For local development\nIf 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:\n\nGradle:\n\n```gradle\ndependencies {\n    testCompile files('../junit-insights/library/build/libs/junit-insights-1.1.0.jar')\n}\n```\nMaven:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ede.adesso\u003c/groupId\u003e\n    \u003cartifactId\u003ejunit-insights\u003c/artifactId\u003e\n    \u003cversion\u003e1.1.0\u003c/version\u003e\n    \u003cscope\u003esystem\u003c/scope\u003e\n    \u003csystemPath\u003e${basedir}/../junit-insights/library/build/libs/junit-insights-1.1.0.jar\u003c/systemPath\u003e\n\u003c/dependency\u003e\n```\n\n# How time is measured\nThe 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](https://junit.org/junit5/docs/5.0.2/api/org/junit/jupiter/api/extension/package-summary.html) as well as the [Spring ContextRefreshedEvent](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/event/ContextRefreshedEvent.html) 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.\n\n![Overview of the captured timestamps](./images/timestamps.svg)\n\nTo further explain the meaning of the timestamps, following is an extract from the help dialog on the top right of the report site.\n\nThe **Overview** chart breaks down the total test time into the following components:\n- ![](https://placehold.it/15/6db33f/000000?text=+) **Spring**: startup time for all Spring application contexts\n- ![](https://placehold.it/15/eedf7b/000000?text=+) **Preparation**: sum of all time that passed before the BeforeAll and BeforeEach callbacks\n- ![](https://placehold.it/15/dc524a/000000?text=+) **Execution**: sum of all time that passed between the BeforeEach and AfterEach callbacks\n- ![](https://placehold.it/15/eac950/000000?text=+) **Tear-Down**: like preparation but after the execution\n\nThe list down below shows an overview of the **individual tested classes** and the time spent on different tasks:\n- ![](https://placehold.it/15/6db33f/000000?text=+) **Spring**: startup time of the possibly created Spring application context\n- ![](https://placehold.it/15/3c7da0/000000?text=+) **Before All**: tasks executed before any of the test methods are executed\n- ![](https://placehold.it/15/eedf7b/000000?text=+) **Before**: sum of the time used before each individual test method\n- ![](https://placehold.it/15/dc524a/000000?text=+) **Exec**: sum of the execution time of all test methods\n- ![](https://placehold.it/15/eac950/000000?text=+) **After**: like before but after the execution\n- ![](https://placehold.it/15/82b4d0/000000?text=+) **After All**: like before all but after the execution\n\nYou can also expand the test classes and get the information about ![](https://placehold.it/15/eedf7b/000000?text=+) **Before**, ![](https://placehold.it/15/dc524a/000000?text=+) **Execution** and ![](https://placehold.it/15/eac950/000000?text=+) **After** for the individual test methods.\n\n# Troubleshooting\n\nIf you get an error complaining about a missing JUnit platform launcher, for example\n\n```\njava.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener\n```\nyou need to add the dependency for the [appropriate package](https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher).\n\nIf you have any other issues, feel free to open an issue in our issue tracker.\n\n# Screenshot\n![Screenshot 1](./images/screen1.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadessose%2Fjunit-insights","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadessose%2Fjunit-insights","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadessose%2Fjunit-insights/lists"}