Hey folks, I'm trying to write some tests for comp...
# compose
g
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
a
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
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
Copy code
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
Copy code
onNodeWithText("No data available").assertIsDisplayed()
a
Are you calling it on the
ComposeTestRule
?
g
@Adam Powell I was following https://developer.android.com/jetpack/compose/testing but I'll try calling it on the rule
a
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 ☝️
👍 1
g
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 😆
🎉 1
Progress is progress right? ;)
o
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