Skip to content

Support JaCoCo aggregated reports in test coverage visualization

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Proposal

Add support for JaCoCo aggregated reports in test coverage visualization.

Follows #227345 (closed) (and mentionned in #479804 (comment 2116912208)).

The current process works great in multi module projects if there are multiple JaCoCo reports, one in each module (see #227345 (comment 2059938471)).

  • module1
    • target/jacoco-report/jacoco.xml
  • module2
    • target/jacoco-report/jacoco.xml

For my projects, I have a different architecture. I have a report module that aggregate reports into a single one.

  • module1
  • module2
  • report (includes module1 and module2)
    • target/jacoco-report/jacoco.xml

The HTML report looks like this:

report

Reproducer

See project https://gitlab.com/jdussouillez/gitlab-jacoco-report-aggregate

  • PR #1: Test coverage visualization doesn't work because I use the aggregated report. code

PR1

  • PR #2: Test coverage visualization works because I use both module1 and module2 reports and not the one aggregated. code

PR2

Reports

Here the structure of a report for a single module:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd">
<report name="myapp-module1">
    <package name="com/gitlab/jdussouillez/module1">
        <!-- [...] -->
    </package>
    <!-- [...] -->
</report>

And for an aggregate:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd">
<report name="myapp">
    <group name="myapp-module1">
        <package name="com/gitlab/jdussouillez/module1">
            <!-- [...] -->
        </package>
        <!-- [...] -->
    </group>
    <group name="myapp-module2">
        <package name="com/gitlab/jdussouillez/module2">
            <!-- [...] -->
        </package>
        <!-- [...] -->
    </group>
    <!-- [...] -->
</report>

Implementation Guide

Cases to handle

  • If the <group> tag's name attr always contains the root dir's name, e.g. the directory names at the root of your project myapp-module1, myapp-module2,it allows us to infer the file in the edge case of having 2 files with identical paths, aside from their root dirs.

e.g. module-1/src/main/java/com/gitlab/jdussouillez/acme, my-app-module-2/src/main/java/com/gitlab/jdussouillez/acme

  • If the <group> tag's name attr doesn't contain the root dir's name, we can't support the above case and it will be a limitation to add to the docs.

We need to confirm with the JaCoCo maintainers if the group can be customized and if it is always populated when using the report-aggregate goal on the maven config.

Resources

Edited by 🤖 GitLab Bot 🤖