An open API service indexing awesome lists of open source software.

https://github.com/surpsg/diff-coverage-maven-plugin

Maven plugin for computing code coverage on modified code
https://github.com/surpsg/diff-coverage-maven-plugin

code-coverage coverage diff diff-coverage jacoco java kotlin maven maven-plugin

Last synced: about 23 hours ago
JSON representation

Maven plugin for computing code coverage on modified code

Awesome Lists containing this project

README

        

# diff-coverage-maven-plugin

[![Release](https://github.com/SurpSG/diff-coverage-maven-plugin/actions/workflows/release.yml/badge.svg)](https://github.com/SurpSG/diff-coverage-maven-plugin/actions/workflows/release.yml)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.surpsg/diff-coverage-maven-plugin.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.surpsg%22%20AND%20a:%22diff-coverage-maven-plugin%22)
[![codecov](https://codecov.io/gh/SurpSG/diff-coverage-maven-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/SurpSG/diff-coverage-maven-plugin)

`Diff coverage maven plugin` builds [JaCoCo](https://github.com/jacoco/jacoco) compatible code coverage report of new and modified code based on a provided [diff](https://en.wikipedia.org/wiki/Diff#Unified_format).

The plugin is able to check and fail a build if code coverage rules are not met.

## How it works
`Diff coverage` works in tandem with JaCoCo and requires JaCoCo to be applied to a project as well.
The plugin does the next steps:
* analyzes coverage data('.exec' files generated by JaCoCo)
* cuts off all code coverage data that wasn't modified
* checks violation rules if any are set up
* builds diff coverage HTML report. See [HTML report example](#Report-example)

## Install plugin
```xml



org.jacoco
jacoco-maven-plugin
0.8.10


io.github.surpsg
diff-coverage-maven-plugin
1.0.0




path/to/diffFile


HEAD


http://url.com





true


0.7



0.1
0.7
1.0


**/custom/exec/location/*.exec


**/custom/**/exclude/*.exec



**/package/**
**/ClassNamePrefix*



**/exclude/**/ClassName.class








html
false







diffCoverage




```

## Maven goal description
`Diff Coverage Maven plugin` has a single goal `diffCoverage` that is bind to `verify` phase
```shell script
# run tests and build diff coverage report
mvn clean verify

# Invoke the goal explicitly.
# It depends on `test` phase, make sure it's called when coverage data(*.exec files) already generated.
mvn clean test diff-coverage:diffCoverage
```

## Report example
Maven output on failed violation rules:
```
[INFO] File src/main/kotlin/org/example/Hello.kt has 5 modified lines
[INFO] New violation: Rule violated for bundle untitled: instructions covered ratio is 0.4, but expected minimum is 0.7
[INFO] New violation: Rule violated for bundle untitled: lines covered ratio is 0.6, but expected minimum is 0.7
[WARNING] Fail on violations: true. Found violations: 2.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.919 s
[INFO] Finished at: 2020-07-06T00:56:33+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Rule violated for bundle TestProj: instructions covered ratio is 0.4, but expected minimum is 0.7
[ERROR] Rule violated for bundle TestProj: lines covered ratio is 0.6, but expected minimum is 0.7
```
The plugin creates JaCoCo like HTML, XML and CSV reports in directory `target/site/diffCoverage/`.

DiffCoverage HTML report

JaCoCo HTML report
JaCoCo HTML report