How can I check if a radio button is selected in Jetpack Compose UI tests?

1.2k Views Asked by At

Does anybody know how to check, which radio button is selected in Android UI tests for Jetpack Compose created UI?

I made a radio button group via the attached code, but I don't know how to identify which one is selected by the UI tests.

Column(Modifier.selectableGroup()) {....}

Is there some kind of assertion that returns the selected radio button of the radio button group?

1

There are 1 best solutions below

2
On

Just set the onClick property of the RadioButton to some callback provide an id to identify what button is selected:

@Composable
fun MyRadioButton(
   onClick: (id) -> Unit
) {
    RadioButton(
        onClick = {
            onClick("myRadioButtonId")
        }
    )
}