What is Espresso Testing? How does it work?

On This Page What is Espresso Framework?Components of EspressoFebruary 16, 2026 · 4 min read · Testing Guide

What is Espresso Testing? How do it work?

.Espresso tryis Google ’ s framework for Android UI automation. It insure fast, reliable, and developer-friendly tests by syncing actions with the app ’ s UI.

Overview

1. What is Espresso Testing Framework and Why It Matters?

  • Google ’ s official Android UI automation framework.
  • Provides asimpleton, honest APIto test user interaction.
  • Automatically synchronizes with the app ’ s UI ribbon → fewer flaky tests.
  • Ensures faster, more accurate test results compare to manual testing or precarious scripts.

2. What are the Core Components of Espresso?

  • Espresso API→ Entry point (onView (), onData ()).
  • ViewMatchers→ Identify UI ingredient (withId (), withText ()).
  • ViewActions→ Perform actions (click (), typeText ()).
  • ViewAssertions→ Validate UI states (isDisplayed (), matches ()).

3. How to Set Up and Run Espresso Tests Step by Step?

  1. Turn off animations(via twist settings or ADB).
  2. Add dependencies in app/build.gradle (espresso-core, runner, rules).
  3. Configure instrumentation runner (AndroidJUnitRunner).
  4. Write test cases with ActivityScenarioRule→ perform clicks, validate UI changes.
  5. Run testsin Android Studio on emulator/real device.

This article explains what Espresso Testing is, its core components, setup process, and how to create and run tests efficaciously. It likewise covers integration with BrowserStack for scarper Espresso tests on real Android devices to ensure accuracy.

What is Espresso Framework?

Testing Framework is an open-source framework created by Google for Android that allows QA to publish tests on the user interface. It has a elementary API, which easily adapt to the testing want, and eliminates the complexity of managing different threads.

Espresso mechanically sync test actions with the UI of the application. The framework besides ensures that your activity is started before the tests and closes after the tests run is completed. For this, Espresso provides@Rulevariable to set up theActivityTestRuleobjects. It also let the test delay until all observed ground activity have terminate.

Read More:

Components of Espresso

The chief components of Espresso include:

  • Espresso– It is an Entry point for interactions with panorama (viaonView () and onData ()). It also exposes APIs that are not necessarily draw to any view, such aspressBack (), pressBackUnconditionally (), etc.
  • ViewMatchers – It allows you to find an particular in the view using different property like Id, Text, etc.
  • ViewActions– It permit you to execute actions on the elements such asclick(), typeText (), etc.
  • ViewAssertions– It validates a view province i.e., whether it is displayed or not.

For exemplar,

withId (R.id.my_view) is a ViewMatcherin the below command

onView (withId (R.id.my_view_id))

click() is a ViewActionin the following command

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

.perform (click ())

matches (isDisplayed ()) is a ViewAssertion

.check (matches (isDisplayed ()));

How to set up Espresso?

To set up Espresso for running automated test on Android Mobile Applications, postdate the below steps:

Set up your test environment

To avoid flakiness, It is highly recommended to become off system animations on the physical or virtual devices used for testing. On the device, underSettings & gt; Developer alternative, disenable the below following three background:

  • Window animation scale
  • Transition animation scale
  • Animator duration scale

Another way to do this is by running the below adb bidding:

adb shell settings put world-wide window_animation_scale 0.0
adb shell scope put global transition_animation_scale 0.0
adb shell settings put global animator_duration_scale 0.0

Add Espresso Dependencies

To add Espresso dependencies to your project, follow the below steps:

Step 1Open your app ’ sbuild.gradlefile where you have remark the dependencies of the app. This is not the top-levelbuild.gradle file but app/build.gradle.

Step 2Add the following code lines inside dependencies:

androidTestImplementation 'androidx.test.espresso: espresso-core:3.4.0' androidTestImplementation 'androidx.test: runner:1.4.0' androidTestImplementation 'androidx.test: rules:1.4.0 '

Set the instrumentality runner

Add to the samebuild.gradlefile the following below line inandroid.defaultConfig:

testInstrumentationRunner `` androidx.test.runner.AndroidJUnitRunner ''

Create Espresso Test for your Android App

Taking a sample app to valuate that on Pressing the button “Add Plant”, Plant List Page open in the adjacent tab. To do so,

  • Create New Java Class file with the nameGardenActivityJavafile in theAndroidTestFolder, where the package name iscom.google.samples.apps.sunflower
  • Add the below code snippet in this New Java Class fileGardenActivityJava.
//Launch the activeness before test @ Rule public ActivityScenarioRule & lt; GardenActivity & gt; activityRule = new ActivityScenarioRule & lt; & gt; (GardenActivity.class); @ Test public void clickAddPlant_OpensPlantList () {// Given that no Plants are add to the exploiter 's garden // When the `` Add Plant '' button is clicked (Yellow Button) onView (withId (R.id.add_plant)) .perform (click ()); // Then the ViewPager should alter to the Plant List page (Plant Page) onView (withId (R.id.plant_list)) .check (ViewAssertions.matches (isDisplayed ())); Espresso.pressBackUnconditionally ();}

Run Espresso Test

To run Espresso Test, you need to create a test configuration in Android Studio using the undermentioned step:

  • Exposed Run menu & gt; Edit Configurations
  • Add a new Android Tests configuration
  • Choose a module
  • Add a specific instrumentation runner using the codification below
android.support.test.runner.AndroidJUnitRunner
  • Add your class gens

Once the configuration is setup connect your twist or select the emulator and directly run the shape.

Integrate with BrowserStack

It is essential to get precise exam results by testing on existent Android devices. It is clip to to conduct existent user conditions into account while testing for better truth. allows you to run your Espresso tests on real android devices, justand get access to thousands of.

Check out the Official Documentation to learn how to.

Leverage the various reward of BrowserStack to run Espresso tests effortlessly. Use BrowserStack ’ s existent android device cloud to ensure that all examination return 100 % accurate results. Don ’ t limit your tests to the various inadequacies of emulators and simulators; simply rely on the existent deal to create customer-ready, meticulously optimized web applications. Integrate it with your CI/CD pipeline and create your Android App user ready seamlessly with every release cycle.

Tags
35,000+ Views

# Ask-and-Contributeabout this issue with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free