Modern Apps git

← Modern-Apps.git

build: give library unit tests the same Robolectric setup as apps

Commit
babbfcc9aba6d9490db893b26c8485992f2f82ba
Author
Vayun Mathur <[email protected]>
When
2026-11-06 18:05 UTC (29 days ago)
Parents
9f90ad4
Library modules never set unitTests.isIncludeAndroidResources or the shared
robolectric.properties, so Robolectric ran them with no merged manifest (package
org.robolectric.default) and on the wrong SDK. Compose tests failed to resolve
ComponentActivity, since ui-test-manifest was a debugImplementation dep and libraries
have no testBuildType. Add both settings and make ui-test-manifest a testImplementation dep.

(cherry picked from commit 71672f058ed5cd618164585040aafce92eca88aa)

Diff

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 e175d7e192..e87a485bc7 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -24,6 +24,13 @@ wireRustHostLibsForUnitTests() includeRobolectricClassesInCoverage()  configure<com.android.build.api.dsl.LibraryExtension> {+    // Same unit-test setup as common-conventions-app: merged manifest/resources for+    // Robolectric, plus the shared robolectric.properties (default sdk).+    testOptions {+        unitTests.isIncludeAndroidResources = true+    }+    sourceSets.getByName("test").resources.srcDir(File(rootDir, "build-logic/shared-test-resources"))+     buildFeatures {         compose = true     }@@ -115,7 +122,7 @@ dependencies {     // Bare ComponentActivity for Robolectric Compose tests (createComposeRule needs the     // manifest entry; the artifact ships only a manifest, no code). Scoped to `debug`,     // the variant unit tests run against.-    debugImplementation(libs.androidx.compose.ui.test.manifest)+    testImplementation(libs.androidx.compose.ui.test.manifest)      // On-device test harness (src/androidTest; e.g. :library:map's renderer harness).     // Same Espresso caveat as the app convention: the compose test artifact is present