RunComposeUiTestSample
@OptIn(ExperimentalTestApi::class)
@Sampled
fun RunComposeUiTestSample() = runComposeUiTest {
var counter by mutableIntStateOf(1)
setContent {
Column {
Text(text = "Count: $counter", modifier = Modifier.testTag("text_tag"))
Button(onClick = { counter++ }, modifier = Modifier.testTag("button_tag")) {
Text("Click Me!")
}
}
}
onNodeWithTag("button_tag").performClick()
onNodeWithTag("text_tag").assert(hasText("Count: 2"))
}
RunComposeUiTestConfigSample
@OptIn(ExperimentalTestApi::class)
@Sampled
fun RunComposeUiTestConfigSample() =
runComposeUiTest(
config =
ComposeUiTestConfig(
effectContext = StandardTestDispatcher(),
runTestContext = StandardTestDispatcher(),
testTimeout = 30.seconds,
inputMode = InputMode.Touch,
)
) {
var counter by mutableIntStateOf(1)
setContent {
Column {
Text(text = "Count: $counter", modifier = Modifier.testTag("text_tag"))
Button(onClick = { counter++ }, modifier = Modifier.testTag("button_tag")) {
Text("Click Me!")
}
}
}
onNodeWithTag("button_tag").performClick()
onNodeWithTag("text_tag").assert(hasText("Count: 2"))
}