diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/build.gradle.kts | 85 |
1 files changed, 81 insertions, 4 deletions
diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e525eea..eba61d1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -99,6 +99,9 @@ android { buildTypes { debug { enableUnitTestCoverage = true + // Produces device coverage data for jacocoFullReport. The commit gate deliberately + // does not read it -- see that task. + enableAndroidTestCoverage = true } release { isMinifyEnabled = false @@ -230,21 +233,95 @@ jacoco { toolVersion = "0.8.12" } +/** + * What coverage does not count. + * + * Compose screens are excluded for the same reason as FeeDreader: they are impractical to + * unit-test and including them makes the metric meaningless. + * + * The rest are framework adapters -- classes whose whole body is a call into ExoPlayer, Media3, + * Room, WorkManager or Chaquopy, none of which can execute on the JVM. They were overridden + * eight times in a row with `COVERAGE_EXCEPTION`, and the last few were perverse: extracting + * decisions *out* of a service into tested classes lowered the number, and writing an + * instrumented test for a migration lowered it again. A metric that punishes both is measuring + * how much Android glue exists rather than how well the logic is tested. + * + * **Adding to this list needs a reason, not just a name.** The bar is "cannot execute off a + * device", not "awkward to test" -- QueueRepository, PlaybackAdvancer, EpisodeDownloader and + * ChapterFetcher all touch framework-adjacent things and all stay measured, because their + * logic runs fine against fakes. + */ +val coverageExclusions = listOf( + "**/ui/**", + "**/R.class", "**/R\$*.class", "**/BuildConfig.*", "**/*_Impl*", + + // ExoPlayer, MediaSession and the browse tree: no JVM equivalent to run against. + "**/playback/PlaybackService*", + "**/playback/PlayerConnection*", + "**/playback/ListenSessionCallback*", + "**/playback/LibraryTree*", + "**/playback/NotificationControls*", + "**/playback/PodcastPlayer*", + + // Room's own machinery, including the migrations -- proven on a device by MigrationTest. + "**/data/AppDatabase*", + + // WorkManager entry points; the decisions live in DownloadDrainer, RetentionSweeper and + // QueuedDownloads, which are measured. + "**/work/RefreshWorker*", + "**/work/DownloadWorker*", + "**/work/RetentionWorker*", + "**/work/Scheduling*", + + // The embedded CPython bridge, and the app/graph wiring that only constructs things. + "**/download/ChaquopyAudioSource*", + "**/youtube/YouTubeAudio*", + "**/data/Graph*", + "**/data/AppGraph*", + "**/ListenApp*", +) + tasks.register<JacocoReport>("jacocoTestReport") { dependsOn("testDebugUnitTest") reports { xml.required.set(true) html.required.set(true) } - // ui/** is excluded for the same reason as FeeDreader: Compose screens are impractical to - // unit-test for coverage and including them makes the metric meaningless. val kotlinDebugTree = fileTree("${layout.buildDirectory.get()}/tmp/kotlin-classes/debug") { - exclude("**/ui/**", "**/R.class", "**/R$*.class", "**/BuildConfig.*", "**/*_Impl*") + exclude(coverageExclusions) } val javaDebugTree = fileTree("${layout.buildDirectory.get()}/intermediates/javac/debug") { - exclude("**/ui/**", "**/R.class", "**/R$*.class", "**/BuildConfig.*", "**/*_Impl*") + exclude(coverageExclusions) } classDirectories.setFrom(files(kotlinDebugTree, javaDebugTree)) sourceDirectories.setFrom(files("src/main/java")) executionData.setFrom(fileTree(layout.buildDirectory) { include("**/*.exec") }) } + +/** + * Unit *and* instrumented coverage, for when you want the fuller picture. + * + * Deliberately not what the commit gate reads. Instrumented data only exists after a device run, + * so folding it into the gate would make the number depend on whether one happened recently and + * on stale .ec files lying around -- a gate that reports different figures for identical code is + * worse than a narrow one. Run this with a device attached: + * + * ./gradlew connectedDebugAndroidTest jacocoFullReport + */ +tasks.register<JacocoReport>("jacocoFullReport") { + dependsOn("testDebugUnitTest") + reports { + xml.required.set(true) + html.required.set(true) + } + val kotlinDebugTree = fileTree("${layout.buildDirectory.get()}/tmp/kotlin-classes/debug") { + exclude(coverageExclusions) + } + val javaDebugTree = fileTree("${layout.buildDirectory.get()}/intermediates/javac/debug") { + exclude(coverageExclusions) + } + classDirectories.setFrom(files(kotlinDebugTree, javaDebugTree)) + sourceDirectories.setFrom(files("src/main/java")) + // .ec is what a device run writes, alongside the JVM run's .exec. + executionData.setFrom(fileTree(layout.buildDirectory) { include("**/*.exec", "**/*.ec") }) +} |
