We are in the process of migrating our Android app to Jetpack Compose.
In our legacy Views-based app, we have a lot of androidTest
tests, running on the emulator, using Espresso.
Most of our tests heavily use the Espresso withId()
matcher. But of course since Composables don't have ids as Views do, we have a problem.
Is there a way to assign ids to composables, and reuse existing Espresso tests using withId()
?
If it's not possible or somehow a bad approach, what would be the right way to search for a specific UI element on screen and click on it for instance?
Thank you for your help
You can apply the
testTag
modifier to your composables.Something like:
and then you can use it with: