Testing in Compose

Build your first Jetpack Compose tests. Learn how to use Compose's testing artifacts to write UI tests, use test rules, finders, and assertions.

Key points

  • Compose tests are instrumentation tests, requiring an emulator or device to run.
  • Add testing dependencies in the module's build.gradle file for the project you're testing.
  • Include the composeTestRule to launch components or activities, providing the interface to use the finders, actions, assertions, and more. * Depending on how much you want to interact with the framework in your test, you can use either composeTestRule or AndroidComposeTestRule. When possible, use the composeTestRule.
  • To find an element, use one of the onNode finders and add assertions.
  • Access the launching activity with the activity property in the composeTestRule by calling getString.
  • The testing APIs in Compose let you test in isolation or use time manipulation, and include a list of finders, actions, and assertions.

Parent collections

This series of videos introduces various Compose APIs, quickly showing you what’s available and how to use them.

Have questions or feedback

Go to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts.