Member-only story
Android UI Testing Using Espresso
Developed by Google, is an instrumentation testing framework. This means it runs within your app’s process on a real device or emulator. It treats your app as a white box, allowing you to have more detailed knowledge of its internal structure and implementation. Espresso cheat sheet.
Key Characteristics of Espresso:
White-box Testing:
You have access to your app’s internal components, making it easier to target specific UI elements and verify their states.
Synchronization:
Espresso automatically synchronizes with the UI thread, ensuring that your tests don’t run ahead of the UI, leading to more reliable and less flaky tests. It waits for UI events, animations, and background tasks (if you provide IdlingResources for custom synchronization).
Concise API:
Espresso’s API is designed to be fluent and expressive, making test code relatively easy to read and write. Entry point to interactions with views (via onView()
and onData().
It focuses on three main parts:
ViewMatchers: To locate UI elements on the screen
(e.g., by ID, text, or other properties using onView()).
ViewActions: To perform actions on the matched elements (
e.g., clicking, typing, scrolling using perform()).
ViewAssertions: To verify the state or…