I’m trying to test a composable using .testTag
that sits at the leaf level of the tree given the Composables call structure. The code is in the style of:
Top level Composable
@Composable
fun TopLevelComposable() {
AComposable()
}
Child composable
@Composable
fun AComposable() {
LeafComposable()
}
Leaf Composable
@Composable
fun LeafComposable() {
Text(text = "stringOfText", modifier = Modifier.testTag("Text of AComposable"))
}
MainActivity.kt
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
TopLevelComposable()
}
}
}
}
Though, I get an error:
java.lang.AssertionError: Failed: assertExists.
Reason: Expected exactly '1' node but could not find any node that satisfies: (TestTag = 'Text of AComposable')
However, the unmerged tree contains '1' node that matches. Are you missing `useUnmergedNode = true` in your finder?
Question
How can I enable androidTest to accept nested .testTag
using Composables?