https://kotlinlang.org logo
g

Gabriel

11/03/2020, 7:48 PM
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

Adam Powell

11/03/2020, 7:58 PM
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

11/03/2020, 8:00 PM
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

Adam Powell

11/03/2020, 8:04 PM
Are you calling it on the
ComposeTestRule
?
g

Gabriel

11/03/2020, 8:07 PM
@Adam Powell I was following https://developer.android.com/jetpack/compose/testing but I'll try calling it on the rule
a

Adam Powell

11/03/2020, 8:08 PM
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

Gabriel

11/03/2020, 8:09 PM
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

Oussama Haff.

11/03/2020, 11:23 PM
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
9 Views