compose-samples
compose-samples copied to clipboard
JetNews release unit tests are failing
./gradlew check fails on main branch.
Running on macOS 12.5.1
Tests pass on debug build type, but fail on release build type.
Might consider running ./gradlew check on CI. :)
They fail with this error:
> Task :app:testReleaseUnitTest
com.example.jetnews.HomeScreenTests > postsContainError_snackbarShown FAILED
java.lang.RuntimeException at RoboMonitoringInstrumentation.java:52
com.example.jetnews.JetnewsTests > app_opensArticle FAILED
java.lang.RuntimeException at RoboMonitoringInstrumentation.java:52
com.example.jetnews.JetnewsTests > app_launches FAILED
java.lang.RuntimeException at RoboMonitoringInstrumentation.java:52
com.example.jetnews.JetnewsTests > app_opensInterests FAILED
java.lang.RuntimeException at RoboMonitoringInstrumentation.java:52
4 tests completed, 4 failed
> Task :app:testReleaseUnitTest FAILED
FAILURE: Build failed with an exception.
java.lang.RuntimeException: Unable to resolve activity for Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.jetnews/androidx.activity.ComponentActivity } -- see https://github.com/robolectric/robolectric/pull/4736 for details
at org.robolectric.android.fakes.RoboMonitoringInstrumentation.startActivitySyncInternal(RoboMonitoringInstrumentation.java:52)
at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:40)
at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:265)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:195)
at androidx.test.ext.junit.rules.ActivityScenarioRule.lambda$new$0$ActivityScenarioRule(ActivityScenarioRule.java:70)
at androidx.test.ext.junit.rules.ActivityScenarioRule$$Lambda$0.get(ActivityScenarioRule.java:70)
at androidx.test.ext.junit.rules.ActivityScenarioRule.before(ActivityScenarioRule.java:103)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)
at androidx.compose.ui.test.junit4.AndroidComposeTestRule$apply$1$evaluate$1.invoke(AndroidComposeTestRule.android.kt:148)
at androidx.compose.ui.test.junit4.AndroidComposeTestRule$apply$1$evaluate$1.invoke(AndroidComposeTestRule.android.kt:147)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$AndroidComposeUiTestImpl.withDisposableContent(ComposeUiTest.android.kt:476)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1$1$1$1$1$1$1.invoke(ComposeUiTest.android.kt:294)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.withTextInputService(ComposeUiTest.android.kt:360)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.access$withTextInputService(ComposeUiTest.android.kt:217)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$runTest$1$1$1$1$1$1.invoke(ComposeUiTest.android.kt:293)
The reason they are failing is because ui-test-manifest is in debugImplementation configuration and not in the implementation configuration.
If you turn this
debugImplementation("androidx.compose.ui:ui-test-manifest:1.3.0-beta01")
into this
implementation("androidx.compose.ui:ui-test-manifest:1.3.0-beta01")
Then :app:testReleaseUnitTest will succeed... although this it is not probably desirable to have ui-test-manifest in you release APK.
For that we would have to create a special minified build type with the manifest artifact, and I don't think it's worth it.
create a special minified build type with the manifest artifact might be nice to have an example of that for reference. :)
but if we don't want that, maybe exclude those variants?
would be nice if ./gradlew check and ./gradlew build succeeded. :)
This issue has been automatically marked as stale because it has not had any recent activity. Please comment here if it is still valid so that we can reprioritize it. Thank you for your contributions.
@JoseAlcerreca We wanted to catch proguard serialization or obfuscation issues using our ui tests which we run on both debug and release variants. On Release UI Tests, Compose Navigation was not working due to ui-test-manifest being added as a debug implementation. Do you have any other way of catching such issues using Compose ui tests?
Another possible solution is to disable the testReleaseUnitTest task or exclude it from the check task, although it may not be suitable for everyone.
tasks.withType<AbstractTestTask> {
// Disable unit tests for release build type (Robolectric limitations)
if (name == "testReleaseUnitTest") {
enabled = false
}
}