https://kotlinlang.org logo
#compose
Title
# compose
s

Sher Sanginov

12/23/2021, 1:10 AM
Hey everyone I am running into this error when setting up
androidx
UI testing with compose in my project. Any idea what may be wrong? I tried to play with dependencies but no success.
Copy code
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.myapp.debug.test/androidx.activity.ComponentActivity }
	at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:387)
 ...
Full stacktrace in thread.
Copy code
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.myapp.debug.test/androidx.activity.ComponentActivity }
	at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:387) at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:416)
	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(Unknown Source:2)
	at androidx.test.ext.junit.rules.ActivityScenarioRule.before(ActivityScenarioRule.java:103)
	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
	at androidx.compose.ui.test.junit4.AndroidComposeTestRule$AndroidComposeStatement.evaluateInner(AndroidComposeTestRule.android.kt:357)
	at androidx.compose.ui.test.junit4.AndroidComposeTestRule$AndroidComposeStatement.evaluate(AndroidComposeTestRule.android.kt:346)
	at androidx.compose.ui.test.junit4.android.EspressoLink$getStatementFor$1.evaluate(EspressoLink.android.kt:63)
	at androidx.compose.ui.test.junit4.IdlingResourceRegistry$getStatementFor$1.evaluate(IdlingResourceRegistry.jvm.kt:160)
	at androidx.compose.ui.test.junit4.android.ComposeRootRegistry$getStatementFor$1.evaluate(ComposeRootRegistry.android.kt:150)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
My Test:
Copy code
import androidx.compose.ui.test.junit4.createComposeRule

class SomeTest : ScreenshotTest {

    @get:Rule
    val composeRule = createComposeRule()

    @Test
    fun rendersTheDefaultComponent() {
        composeRule.setContent {
            MyAppTheme {
              Surface(color = MaterialTheme.colors.background) {
                  Text(greeting)
              }
            } 
        compareScreenshot(composeTestRule)
        }
My dependencies:
Copy code
implementation "androidx.core:core-ktx:1.3.2"
    implementation "androidx.appcompat:appcompat:1.2.0"
    implementation "com.google.android.material:material:1.3.0"
    implementation "androidx.compose.ui:ui:$composeVersion"
    implementation "androidx.compose.material:material:$composeVersion"
    implementation "androidx.compose.ui:ui-tooling:$composeVersion"
    implementation "androidx.activity:activity-compose:1.3.0-alpha05"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"

    testImplementation "junit:junit:4.13.1"

    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$composeVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
    androidTestImplementation "androidx.test:core-ktx:1.3.0"
    androidTestImplementation "androidx.test:core:1.3.0"
    androidTestImplementation "androidx.test:runner:1.3.0"
    androidTestImplementation "androidx.test.ext:junit:1.1.2"
    androidTestImplementation "androidx.test.ext:junit-ktx:1.1.2"
a

Albert Chang

12/23/2021, 1:28 AM
You need
debugImplementation("androidx.compose.ui:ui-test-manifest:$composeVersion")
as per the doc.
Also please read this.
s

Sher Sanginov

12/23/2021, 1:36 AM
thanks @Albert Chang that fixes the issue
👍 2
70 Views