Modern Apps git

← Modern-Apps.git

build-logic: exclude compile-only aosp-stubs from merged coverage (#tests)

Commit
95a31d13ba61ba0891a693e7824acae3928b7c95
Author
Vayun Mathur <[email protected]>
When
2026-11-16 14:33 UTC (19 days ago)
Parents
ba2f734
library/aosp-stubs is compile-only: 37 @SystemApi/hidden-API stub
classes that consumers take with compileOnly, never packaged into
an APK, replaced at runtime by the framework's real classes. Its
merged coverage could only ever measure tests asserting that stub
bodies throw, for classes that never run - so the honest answer
is no report at all, not 0% and not stub-throw tests.

Add COMPILE_ONLY_STUB_MODULES (just :library:aosp-stubs) in
TestCoverage.kt with the full rationale, and suppress the merged
report task for listed modules in common-conventions-library via
onlyIf. Deliberately a module list, not a class-file pattern: an
android-package exclude would hide real code elsewhere, and
:library:locationprovider - also compile-only stubs, but with a
real contract test suite - stays counted (now at 100%).

Verified: :library:aosp-stubs createMergedCoverageReport (task
skipped, no report), testDebugUnitTest, lint and detekt green;
:library:work:createMergedCoverageReport still produces its
report, so the convention change does not regress other modules.

Diff

build-logic/src/main/kotlin/TestCoverage.kt
diff --git a/build-logic/src/main/kotlin/TestCoverage.kt b/build-logic/src/main/kotlin/TestCoverage.ktindex 15359cdd84..e010e7c7f4 100644--- a/build-logic/src/main/kotlin/TestCoverage.kt+++ b/build-logic/src/main/kotlin/TestCoverage.kt@@ -44,6 +44,32 @@ const val MERGED_COVERAGE_JACOCO_VERSION = "0.8.14"  */ const val ROBOLECTRIC_DEFAULT_SDK = 34 +/**+ * Modules whose merged coverage report is suppressed entirely.+ *+ * `:library:aosp-stubs` is compile-only: its classes are `@SystemApi`/hidden-API+ * stubs that consumers depend on with `compileOnly`, they are never packaged+ * into an APK, and at runtime the framework's real implementations replace+ * them (see that module's `build.gradle.kts`). Its stub bodies either throw+ * `RuntimeException("stub")` or are signature-only shells, so a coverage+ * percentage for it can only measure how much of a compile-time fiction the+ * tests exercised — the number has no runtime meaning, and chasing it would+ * mean writing tests that assert stubs throw, forever, for 37 classes.+ *+ * This is deliberately a module list, not a class-file pattern: a broad+ * `android/...` exclude would also hide real code in any module that ever+ * legitimately shadows a framework package. `:library:locationprovider`+ * is also compile-only stubs but is NOT listed: it has a real test suite+ * pinning the stub contract its consumers subclass against, so its report+ * stays meaningful and counted.+ *+ * The suppression lives in `common-conventions-library` (the only convention+ * that registers a merged report for these modules) as an `onlyIf` on the+ * report task: with no report file, coverage tooling treats the module as+ * not-a-coverage-module rather than as 0%.+ */+val COMPILE_ONLY_STUB_MODULES: Set<String> = setOf(":library:aosp-stubs")+ /**  * Class-file excludes applied to every merged coverage report.  *
build-logic/src/main/kotlin/common-conventions-library.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts b/build-logic/src/main/kotlin/common-conventions-library.gradle.ktsindex e87a485bc7..fd64ccba6a 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -176,6 +176,14 @@ tasks.register<JacocoReport>(MERGED_COVERAGE_TASK) {     } } +// Compile-only stub modules have no meaningful merged coverage; see+// COMPILE_ONLY_STUB_MODULES in TestCoverage.kt for the rationale.+if (project.path in COMPILE_ONLY_STUB_MODULES) {+    tasks.named(MERGED_COVERAGE_TASK) {+        onlyIf("compile-only stub module (see TestCoverage.kt)") { false }+    }+}+ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {     compilerOptions.optIn.addAll(         "androidx.compose.material3.ExperimentalMaterial3Api",