Collect coverage reports per test case execution instead of the entire test suite.
This is a gradle plugin that works with JUnit 5 and Jacoco.
-
Add this plugin (and Jacoco) to the plugins section of your Gradle.
Kotlin:
plugins { jacoco id("io.testaxis.coveragepertest") version "1.0.0" }
Groovy:
plugins { id 'jacoco' id "io.testaxis.coveragepertest" version "1.0.0" }
-
Set the tool version of Jacoco to the version below or higher.
Kotlin/Groovy:
jacoco { toolVersion = "0.8.6" }
-
Set JUnit's extension autodetection property to true to enable the runtime.
Kotlin:
tasks.withType<Test> { systemProperty("junit.jupiter.extensions.autodetection.enabled", "true") useJUnitPlatform() }
Note that the runtime interferes with regular coverage reports. Enable the runtime dynamically if you want to generate a regular coverage report for your entire test suite.
-
Optionally, configure any of the options of the plugin below. You can leave the configuration block out if you do not want to set any custom options.
Kotlin:
coveragePerTestConfig { inputDirectory.set(file("/custom-reports-input-directory")) outputDirectory.set(file("/custom-reports-output-directory")) }
Run tests and generate coverage reports per test:
$ gradlew test coveragePerTest
By default, the reports will be located in build/coveragepertest/xml
.
The plugin consists of two parts: the actual Gradle plugin (plugin-build/
) and the runtime library (runtime/
).
Run the tests and static analysis tools:
$ gradlew preMerge
If you discover any security related issues, please email mail@casperboone.nl instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.