Accessibility testing

When customizing your app's semantic properties, for example when following the use cases listed in the semantics guide, verify correctness and prevent regressions by using automated UI tests.

For example, to test that an element's click label is set correctly, use the following code:

@Test
fun test() {
    composeTestRule
        .onNode(nodeMatcher)
        .assert(
            SemanticsMatcher("onClickLabel is set correctly") {
                it.config.getOrNull(SemanticsActions.OnClick)?.label == "My Click Label"
            }
        )
}

Compose testing

For more information on testing in Compose, see the dedicated testing guides.

Additional resources