Skip to content

build: migrate unit test coverage from JaCoCo to Kover - #994

Merged
dkhawk merged 1 commit into
mainfrom
build/migrate-jacoco-to-kover
Sep 10, 2026
Merged

dkhawk merged 1 commit into
mainfrom
build/migrate-jacoco-to-kover

Conversation

@kikoso

@kikoso kikoso commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Migrates unit test coverage from JaCoCo to kotlinx-kover 0.9.9.

Why: the jacocoTestReport task in PublishingConventionPlugin hardcoded AGP 9 internal intermediate paths (intermediates/built_in_kotlinc/debug) to work around JaCoCo not understanding the built-in Kotlin compiler output. Those paths are implementation details that can break on any AGP update. Kover (first-party JetBrains, actively maintained against AGP 9) integrates through AGP's variant APIs, so the manual report wiring is deleted. The unused com.mxalbert.gradle:jacoco-android classpath dependency (last released for AGP 8.x) is removed as well.

Changes

  • PublishingConventionPlugin applies org.jetbrains.kotlinx.kover with androidGeneratedClasses() excluded, replacing the hand-rolled jacocoTestReport task.
  • test.yml runs koverXmlReportDebug instead of jacocoTestReport.
  • Unchanged: the instrumented-test coverage in instrumentation-test.yml (createDebugCoverageReport on maps-app) uses AGP's built-in on-device JaCoCo, which Kover does not replace, so it stays as is.

Verification

Full CI command ./gradlew build koverXmlReportDebug -x :maps-app:generateDebugScreenshotTestConfig -x :maps-app:generateReleaseScreenshotTestConfig --stacktrace passes locally (11m 51s). Kover reports generate for all three library modules; maps-compose-utils (the only module with host unit tests) shows captured coverage, and the modules without host tests report 0% exactly as JaCoCo did.

@kikoso
kikoso requested a review from a team as a code owner September 10, 2026 12:53
Replaces the manual JaCoCo wiring in PublishingConventionPlugin with
kotlinx-kover 0.9.9. The old jacocoTestReport task hardcoded AGP 9
internal intermediate paths (intermediates/built_in_kotlinc) to work
around JaCoCo not understanding the built-in Kotlin compiler output;
Kover integrates through AGP's variant APIs so none of that is needed.

Also removes the unused com.mxalbert.gradle:jacoco-android classpath
dependency (last released for AGP 8.x).

CI now runs koverXmlReportDebug for the library modules. The
instrumented-test coverage in instrumentation-test.yml is unchanged:
it uses AGP's built-in on-device JaCoCo, which Kover does not cover.
@kikoso
kikoso force-pushed the build/migrate-jacoco-to-kover branch from aabb831 to a990ea6 Compare September 10, 2026 13:07
@googlemaps-bot

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 24.59% ❌

There is no coverage information present for the Files changed

@dkhawk
dkhawk merged commit 2344932 into main Sep 10, 2026
13 checks passed
@dkhawk
dkhawk deleted the build/migrate-jacoco-to-kover branch September 10, 2026 17:28
kikoso added a commit that referenced this pull request Sep 15, 2026
* ci: record unit and instrumentation test coverage history

Coverage was reported per run but never retained, so there was no way to
see how it moves over time. This adds an append-only history that is
updated after every merge to main.

coverage/history.csv holds one row per module per suite per merged commit.
coverage/COVERAGE.md is regenerated from it with the current numbers and a
trend table. Both are produced by .github/scripts/coverage_history.py,
which parses the JaCoCo-format XML that both Kover and AGP emit.

Two suites are tracked separately, since they instrument different code
and cannot be merged from their XML reports:

  unit             koverXmlReportDebug, covering the library modules
  instrumentation  createDebugCoverageReport, covering maps-app and
                   maps-compose-widgets

Instrumentation tests are not re-run after merge. The emulator already
runs on every pull request, so instrumentation-test.yml now publishes its
reports as an artifact and the post-merge workflow downloads it. That
keeps the added CI cost at roughly zero. If the run is missing or the
artifact has expired, only unit coverage is recorded for that commit.

Pull requests also get a sticky comment showing the unit coverage delta
against main. Instrumentation already has its own comment.

Release-please commits are skipped so releases do not add entries.

Also corrects a stale jacocoTestReport reference in AGENTS.md left over
from the Kover migration in #994.

* ci: bind workflow expressions through env to fix template injection

zizmor flagged github.base_ref being expanded directly into a run block in
test.yml as a high severity template-injection finding. Branch names can
contain shell metacharacters, so the value is now passed through the step
environment and referenced as a shell variable instead.

github.sha in coverage-history.yml is bound the same way. It was not
flagged, since it is always a hex digest, but this keeps run blocks free
of any template expansion.

Also notes why the checkout in coverage-history.yml keeps its credentials:
the job pushes the updated history back to main.

* ci: add thousands separators to coverage tables

Large line counts were hard to read at a glance: 2731/5405 rather than
2,731/5,405. Only the rendered markdown changes; history.csv keeps raw
numbers so it stays machine readable.

A comma is used rather than a dot because the tables already spell
percentages with a decimal point, and reusing the dot for both roles would
make a number like 2.731 ambiguous.

Also regenerates COVERAGE.md, which had been committed with a timestamp
one render out of step with history.csv.

* ci: limit instrumentation coverage to modules that own androidTest

createDebugCoverageReport emits a report for every module with
enableAndroidTestCoverage, including maps-compose and maps-compose-utils,
which have no androidTest sources at all. Those reports list every class
at 0%, which reads as "untested" when the code is in fact exercised by
maps-app's tests and simply attributed there.

Recording them dragged the instrumentation total from 20.83% down to
10.08% and said something false about the libraries. The suite now tracks
maps-app and maps-compose-widgets, the two modules that actually own
instrumentation tests, which also matches the figure the existing coverage
comment reports.

Verified against the real artifact from run 34986287391 rather than a
fixture: maps-app 21.73%, maps-compose-widgets 6.71%, total 20.83%.

Adds a --modules override ("all" records every module) so the scope can be
changed without editing the parsing code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants