JaCoCo is a free Java code coverage library distributed under the Eclipse Public License. Check the project homepage for downloads, documentation and feedback.
Please use our mailing list for questions regarding JaCoCo which are not already covered by the extensive documentation.
Note: We do not answer general questions in the project's issue tracker. Please use our mailing list for this.
On the fly logic for removing methods. All methods which are not part of their source file are removed from JaCoCo bundle.
JaCoCo report contains big amount of inherited methods which is not needed/expected to cover by tests.
jacoco.exec
file (as JaCoCo bundle data source)- built class files (as JaCoCo bundle data source)
- source class files (as source of truth for method filtration)
- reduced JaCoCo bundle as a source for report generation
<execution>
<id>jacoco-report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<title>${project.name} - ${scala.version}</title>
<doMethodFiltration>true</doMethodFiltration>
<doScalaMethodFiltration>true</doScalaMethodFiltration>
<doManualScalaMethodFiltration>true</doManualScalaMethodFiltration>
<srcRootDir>src/main/scala</srcRootDir>
<methodExcludes>
<exclude>com/package/patk/Classname@methodName</exclude>
</methodExcludes>
</configuration>
</execution>
org.jacoco.core.analysis.CoverageBundleMethodFilterConst.java
org.jacoco.core.analysis.CoverageBundleMethodFilterScalaImpl.java
org.jacoco.core.analysis.ClassCondensate.java
org.jacoco.core.analysis.CoverageBundleMethodFilterScalaImplTest.java
KEPT_by_SKIP_CLASS_NAME
KEPT_by_SKIP_METHOD_NAME
KEPT_by_EXISTING
KEPT_by_EXCEPTION
REMOVED_by_SKIP_CLASS_NAME_INIT_METHOD
REMOVED - not found in class file.
REMOVED - not found in classCondensate.
REMOVED_BY_MANUAL_EXCLUDE - manually defined to remove from report
Implemented filtration logic does not contain all possible scala code combinations. All class elements are removed if they are not found in source files. This can lead to unexpected removes of logic. Suggestion for usage:
- Generate two JaCoCo reports: switched on/off method filtration.
- Do comparison of results.
- If you identify missing method after filtration collect inputs and provide them to us to improved logic.
- When used on project with Github Action madrapps/jacoco-report@v1.3 then overall % can be different. Detected 5% difference.
Until Scala method filtering solution will be available in official library. You can use this workaround.
- Checkout this repository.
- Call
mvn install
in repository root dir. - New snapshots should be available on path
$HOME/.m2/repository/za/co/absa/jacoco/*
- Optional: add new version property in your
pom.xml
file
<jacoco.version>0.8.10</jacoco.version>
- add new
profile
section in yourpom.xml
file
<profile>
<id>code-coverage</id>
<properties>
<scalatest.argLine>${default.scalatest.argLine} ${argLine}</scalatest.argLine>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
<build>
<plugins>
<plugin>
<groupId>za.co.absa.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<title>${project.name} - ${scala.version}</title>
<doMethodFiltration>true</doMethodFiltration>
<doScalaMethodFiltration>true</doScalaMethodFiltration>
<doManualScalaMethodFiltration>true</doManualScalaMethodFiltration>
<methodExcludes>
<exclude>com/path/ClassName@methodName</exclude>
</methodExcludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
- to activate JaCoCo report generation call
mvn clean verify -Pcode-coverage
- For JaCoCo with sbt continue with steps in project AbsaOSS/sbt-jacoco