g

    Gabriel

    1 year ago
    Hey folks, I'm trying to write some tests for compose but I'm not sure what dependency to include for onNodeWithText to work. I've got
    androidTestImplementation("androidx.ui:ui-test:$COMPOSE_VERSION")
    but it won't import anything or even mark it as not being imported, I'm not sure what I'm missing
    Unresolved reference: onNodeWithText
    I add
    import androidx.compose.ui.test.onNodeWithText
    but not sure what package to depend on for it, if I try
    androidTestImplementation("androidx.compose.ui:ui-test:$COMPOSE_VERSION")
    then I get
    Failed to resolve: androidx.compose.ui:ui-test:1.0.0-alpha06
    Adam Powell

    Adam Powell

    1 year ago
    Looks like it hasn't been migrated to its new home yet, https://maven.google.com/web/index.html?q=ui-test#androidx.ui:ui-test:1.0.0-alpha06 is probably what you're looking for at the moment
    g

    Gabriel

    1 year ago
    Should it be
    import androidx.ui.test.onNodeWithText
    ? If I import that then it gets removed when I optimise imports
    OK if I disable auto optimise imports it gets further, but now I get
    Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
    public fun ComposeTestRule.onNodeWithText(text: String, ignoreCase: Boolean = ..., useUnmergedTree: Boolean = ...): SemanticsNodeInteraction defined in androidx.ui.test
    onNodeWithText("No data available").assertIsDisplayed()
    Adam Powell

    Adam Powell

    1 year ago
    Are you calling it on the
    ComposeTestRule
    ?
    g

    Gabriel

    1 year ago
    @Adam Powell I was following https://developer.android.com/jetpack/compose/testing but I'll try calling it on the rule
    Adam Powell

    Adam Powell

    1 year ago
    hmm. All of the usages I'm finding in the codebase call it on the rule. @nickbutcher fyi it looks like this page above is outdated
    g

    Gabriel

    1 year ago
    Dag nabbit
    OK I've got it all running now thanks @Adam Powell I mean the test crashes the app somehow but it's running at least 😆
    Progress is progress right? 😉
    Oussama Haff.

    Oussama Haff.

    1 year ago
    I have contributed with some examples for instrumentation tests for Compose in this repo, you can check them out https://github.com/Gurupreet/ComposeCookBook/tree/master/app/src/androidTest/java/com/guru/composecookbook