Skip to main content
Version: 3.0.0

Interoperability with ComposeTestRule

A ComposeTestRule is a TestRule that allows you to test and control composables and applications using Compose. You can read more about Testing your Compose layout here.

The Testify Compose extension provides a default ComposeRule, or you can specify your own.

To specify your own ComposeRule instance, pass the instance to the composeTestRule argument on the ComposableScreenshotRule constructor.

You have access to the ComposeRule instance through the setComposeActions() method. The ComposeRule is provided as the first argument, composeTestRule.

Example

class ComposableScreenshotTest {
@get:Rule
val rule = ComposableScreenshotRule(composeTestRule = createAndroidComposeRule(ComposableTestActivity::class.java))

@ScreenshotInstrumentation
@Test
fun default() {
rule
.setCompose {
var text by remember { mutableStateOf("") }
TextField(
value = text,
onValueChange = { text = it },
modifier = Modifier.testTag("field")
)
}
.setComposeActions { composeTestRule ->
composeTestRule.onNodeWithTag("field").performTextInput("testify")
}
.assertSame()
}
}