CheckOps
Jetpack Compose UI testing
Jetpack Compose's testing APIs (ui-test-junit4) let Android developers find, assert on and interact with composables through semantics, using createComposeRule on devices or with Robolectric on the JVM.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Jetpack Compose, Android’s modern UI toolkit, has its own testing APIs. Google’s documentation explains the key concepts: semantics give meaning to UI so tests can interact with specific elements; testing APIs let you find elements, verify their attributes and perform user actions; and synchronisation means Compose tests wait for the UI to be idle automatically. The docs also cover a cheatsheet, test configuration and execution, interoperability with views, common patterns and debugging.
Tests use a rule created with createComposeRule() (or createAndroidComposeRule<Activity>() when activity access is needed), set content with setContent { ... }, then find nodes with finders such as onNodeWithText, onNodeWithTag and onNodeWithContentDescription, perform actions like performClick() and performTextInput(), and assert with assertIsDisplayed(), assertTextEquals() and others. The dependencies are androidx.compose.ui:ui-test-junit4 plus ui-test-manifest for createComposeRule. The same tests can run as instrumented tests on devices or as local tests with Robolectric, and frameworks such as Kaspresso and Roborazzi build on these APIs.
For debugging, printToLog() dumps the semantics tree, and the merged versus unmerged tree options explain why a finder matches or misses a node.
Features
- Semantics-based finders: Find nodes by text, tag or description.
- Automatic synchronisation: Waits for Compose to be idle.
- Rich assertions and actions: Click, input, scroll and assert.
- Device or JVM: Run on emulators or with Robolectric.
Pros
- Free: Part of AndroidX.
- Built-in sync: Less flakiness from timing issues.
Cons
- Semantics required: Custom components need proper semantics or test tags.
- Compose only: View-based screens need Espresso.
Usage and Links (Example)
androidTestImplementation("androidx.compose.ui:ui-test-junit4:<compose_version>")
debugImplementation("androidx.compose.ui:ui-test-manifest:<compose_version>")
class CounterTest {
@get:Rule val composeTestRule = createComposeRule()
@Test
fun incrementsCounter() {
composeTestRule.setContent { Counter() }
composeTestRule.onNodeWithText("Increment").performClick()
composeTestRule.onNodeWithTag("count").assertTextEquals("1")
}
}
Resources:
Pricing
Free and open source as part of Jetpack Compose (Apache-2.0).
Recommended for?
- Android teams using Jetpack Compose.
- Teams wanting fast Compose tests on the JVM via Robolectric.
Conclusion
Compose’s testing APIs make UI tests concise and reliable, and they are the foundation for most modern Android UI testing.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Jetpack Compose UI testing side by side.
EEspressoEspresso is an Android testing framework for writing concise, beautiful, and reliable UI tests that synchronize automatically with the application's UI.Compare with Jetpack Compose UI testing
RRobolectricRobolectric is an MIT-licensed Android unit testing framework that runs tests in a simulated Android environment inside the JVM, routinely 10x faster than cold-started emulators, supporting 14 Android versions from API 24 to 37.Compare with Jetpack Compose UI testing
KKaspressoKaspresso is Kaspersky's Apache-2.0 Android UI testing framework built on Espresso and UI Automator, adding flaky-test protection, a Kotlin DSL, Compose support, ADB access, detailed reports, Allure and Robolectric support.Compare with Jetpack Compose UI testing
UUI AutomatorUI Automator is Google's Android UI testing framework for cross-app and system UI automation; version 2.4 introduced a modern Kotlin API with a uiAutomator test scope, onElement predicates and built-in waiting.Compare with Jetpack Compose UI testing
PPaparazziPaparazzi is Cash App's Apache-2.0 Android library for rendering application screens without a physical device or emulator, enabling fast screenshot tests on the JVM.Compare with Jetpack Compose UI testing
RRoborazziRoborazzi is an Apache-2.0 Android screenshot testing library that captures screenshots in JVM tests using Robolectric Native Graphics, supporting interactions, Compose and Espresso-style flows.Compare with Jetpack Compose UI testing