Use Espresso to write concise, beautiful, and reliable Android UI tests.
example
@Test
public void greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"));
onView(withId(R.id.greet_button)).perform(click());
onView(withText("Hello Steve!")).check(matches(isDisplayed()));
}
Each time your test invokes onView(), Espresso waits to perform the corresponding UI action or assertion until the following synchronization conditions are met:
AsyncTask currently executing a task.espresso-core - Contains core and basic View matchers, actions, and assertions.espresso-web - Contains resources for WebView support.espresso-idling-resource - Espresso’s mechanism for synchronization with background jobs.espresso-contrib - External contributions that contain DatePicker, RecyclerView and Drawer actions, accessibility checks, and CountingIdlingResource.espresso-intents - Extension to validate and stub intents for hermetic testing.espresso-remote - Location of Espresso’s multi-process functionality.The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app. Espresso Test Recorder then takes the saved recording and automatically generates a corresponding UI test that you can run to test your app.
Espresso Test Recorder writes tests based on the Espresso Testing framework, an API in AndroidX Test. The Espresso API encourages you to create concise and reliable UI tests based on user actions. By stating expectations, interactions, and assertions without directly accessing the underlying app’s activities and views, this structure prevents test flakiness and optimizes test run speed.
To start recording a test with Espresso Test Recorder, proceed as follows:

Assertions verify the existence or contents of a View element through three main types:
To add an assertion to your test, proceed as follows:

use the following steps to save your recording and generate the Espresso test:
If you have not added the Espresso dependencies to your app, a Missing Espresso dependencies dialog appears when you try to save your test. Click Yes to automatically add the dependencies to your build.gradle file.
dependencies {
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
// Optional -- Hamcrest library
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
// Optional -- UI testing with Espresso
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Optional -- UI testing with UI Automator
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
To run an Espresso test, use the Project
window on the left side of the Android Studio IDE:
To run Espresso tests with Firebase Test Lab, create a Firebase project for your app and then follow the instructions
