One Off the Slack: How Do I Write End-to-End Tests?

The indefatigable Colton Idle asked:

I finished my first compose app and now I want to write a few end-to-end tests to test critical paths. App launch. App sign up. App log in. View all movies. Click and view a single movie. That sort of thing.

How do I do that in a pure-compose app? Do I still just use espresso to string together clicks? The compose testing docs seem to be more about testing specific composables.

Google’s Zach Klippenstein replied:

Espresso is gonna be very painful to use for this directly, but you can use it together with the compose testing library (just use createAndroidComposeRule instead of createComposeTestRule)

Google’s Alex Vanyo went in greater depth:

If you’re in a completely pure-Compose app, you will probably find you don’t need Espresso at all. You can interop Espresso with the compose testing library as Zach mentioned, but if you only have Compose elements I don’t think Espresso will be super useful.

Testing specific composables ends up being the easiest and simplest to do (because you can isolate the components and state under test), but you can absolutely use the same set of APIs for larger end-to-end tests. If you put your root composable under test, you can make assertions, perform actions, etc.

JetNews has some very basic end-to-end tests that trigger navigation and check for content on different screens here:

Colton eventually got that working (🎉), albeit with a few hacks. Suffice it to say that it is likely that we will need more to go on for complex tests, such as end-to-end tests.

Read the original thread in the kotlinlang Slack workspace. Not a member? Join that Slack workspace here!