Test Your Android Application Using Espresso

Learn how to navigate automated visual testing onto your Android application using Espresso framework.
April 6, 2026 12 min read
Featured Image Espresso Visual Testing
Home Blog Visual Regression Testing Your Android Applications Using Espresso

Visual Regression Testing Your Android Applications Using Espresso

There are over 24,000 distinct Android device models in the market, running multiple OS versions and custom manufacturer skins. A UI that looks correct on one device can render differently on another due to screen size, pixel density, font rendering, or system-level UI changes.

Manual validation across this diversity is slow, inconsistent, and difficult to scale.

For teams struggling with Android, this is where the Espresso framework becomes essential. Espresso is Google’s native Android UI testing framework that allows developers to automate UI interactions directly within the app process. While primarily built for functional testing, it can also be extended to support visual validation workflows.

This article dives into Espresso for visual testing, where you will understand how to set up Espresso tests for your application. You will also learn how you can integrate an advanced visual testing software like BrowserStack App Percy to culminate the best of both worlds.

What is App Visual Testing?

App visual testing is the practice of verifying that an application’s interface renders correctly under real-world conditions. Instead of checking whether buttons work or APIs respond, it focuses on whether screens look visually accurate across devices and OS versions.

At its core, app visual testing relies on screenshot testing. During execution, the system captures images of app screens and runs a visual comparison test against previously approved baselines. If differences are detected, they are flagged for review.

In Android ecosystems, where screen sizes and densities differ significantly, automated visual validation becomes critical for maintaining consistent user experience.

Deliver the app experience you intended, without visual bugs.

What is Espresso Framework?

Espresso is Google’s official UI testing framework for Android applications. It is designed to automate user interactions within an app and verify that UI components behave as expected. Espresso runs directly inside the app process, which makes tests fast, stable, and tightly integrated with the Android lifecycle.

Unlike external automation tools, Espresso synchronizes automatically with UI threads. It waits for background tasks and UI events to complete before executing the next action. This built-in synchronization reduces flaky tests and improves reliability.

Components of Espresso

The Espresso framework is built around a few core components that work together to interact with and validate Android UI elements.

  • Espresso Core: Espresso acts as the entry point for interacting with views inside the app. Methods like onView() and onData() are used to target UI elements. It also provides global actions such as pressBack() that are not tied to a specific view.
  • ViewMatchers: ViewMatchers help locate UI elements based on specific properties such as ID, text, content description, or class type. They define how Espresso identifies the view you want to interact with.
  • ViewActions: ViewActions perform operations on matched views. These include user-like interactions such as click(), typeText(), scrollTo(), and other input behaviors.
  • ViewAssertions: ViewAssertions validate the state of a view after an action is performed. They confirm conditions such as whether a view is visible, enabled, or contains specific text.

For Example, in the command below:

onView(withId(R.id.my_view_id)).perform(click()).check(matches(isDisplayed()));
  • withId(R.id.my_view_id) is a ViewMatcher
  • click() is a ViewAction
  • matches(isDisplayed()) is a ViewAssertion

Together, these components allow developers to identify a UI element, perform an action on it, and verify the result within a single test flow.

Setting Up Espresso For Visual Testing

Setting up Espresso involves configuring your Android project for stable UI automation and screenshot testing. A proper setup reduces flaky results and ensures reliable visual validation testing across devices.

1. Prepare a Stable Test Environment

Before running Espresso tests, disable system animations on test devices or emulators. Animations can cause inconsistent UI states and unstable screenshot testing results.

On the device, navigate to:

Settings > Developer Options, then disable:

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

Alternatively, use ADB commands:

adb shell settings put global window_animation_scale 0.0

adb shell settings put global transition_animation_scale 0.0

adb shell settings put global animator_duration_scale 0.0

This ensures cleaner visual comparison tests.

2. Add Espresso Dependencies

Open your module-level app/build.gradle file and add the required dependencies inside the dependencies block:

androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

androidTestImplementation 'androidx.test:runner:1.4.0'

androidTestImplementation 'androidx.test:rules:1.4.0'

These libraries enable UI interaction, test execution, and rule-based activity handling.

3. Configure the Instrumentation Runner

Inside the same app/build.gradle file, configure the instrumentation runner in the android.defaultConfig section:

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

This allows Android to execute Espresso tests correctly during automation.

4. Create an Espresso Test Class

Inside the androidTest folder, create a new Java or Kotlin test class. For example, you may create a test to validate that clicking an “Add Plant” button opens the correct screen.

Below is a simplified example:

@Rule

public ActivityScenarioRule<GardenActivity> activityRule =

        new ActivityScenarioRule<>(GardenActivity.class);



@Test

public void clickAddPlant_OpensPlantList() {



    onView(withId(R.id.add_plant)).perform(click());



    onView(withId(R.id.plant_list))

            .check(ViewAssertions.matches(isDisplayed()));



    Espresso.pressBackUnconditionally();

}

This test identifies a button, performs a click action, and validates that the next screen is displayed.

5. Run Espresso Tests

To execute the test:

  • Open Run > Edit Configurations in Android Studio
  • Add a new Android Test configuration
  • Select the correct module
  • Set the instrumentation runner
  • Specify the test class

Connect a physical device or launch an emulator, then run the configuration. Once set up, these tests can be extended to include screenshot testing and automated visual comparison workflows.

It takes less than a second for your users to catch issues on your app. It only takes slightly more to sign up with App Percy.

Benefits of Espresso Visual Testing

Espresso provides a stable foundation for Android UI automation. When extended with snapshot testing and visual comparison workflows, it becomes a powerful mechanism for validating UI consistency.

Below are the key benefits of using Espresso for visual regression testing in Android applications:

  • Native Android Integration: Espresso runs directly inside the Android app process, which ensures deep integration with the activity lifecycle and UI thread. This reduces synchronization issues and creates a reliable foundation for capturing consistent screenshots during tests.
  • Automatic UI Synchronization: Espresso automatically waits for background tasks and UI events to complete before executing actions. This built-in synchronization minimizes flaky results and ensures that screenshots capture stable UI states rather than partially rendered screens.
  • Fast Test Execution: Because Espresso operates within the app context instead of through an external driver, tests execute quickly. Faster execution improves feedback loops and makes frequent visual diffing practical within continuous integration pipelines.
  • Reliable View Targeting: ViewMatchers allow precise identification of UI elements using attributes such as ID or text. Accurate targeting ensures that it captures the correct screen state before ensuring UI accuracy.
  • Seamless CI Integration: Espresso tests integrate easily with Android build systems and CI/CD workflows. Automated visual tests can run automatically on every commit, helping teams detect unintended UI changes early in development.
  • Flexible Extension: Although primarily a functional testing framework, Espresso can be extended with snapshot libraries. This allows teams to switch to a separate automation tool conveniently.
  • Strong Community and Documentation: Espresso is officially supported by Google and widely adopted in Android development. Extensive documentation and community resources help teams implement stable visual testing workflows more effectively.

Limitations of Espresso Visual Testing

While Espresso provides a stable and reliable framework for Android UI automation, it has certain limitations when used for visual testing. However, most of these surfacing issues can be solved by an external software integration, like BrowserStack App Percy.

Here are the challenges:

  • Android-Only Coverage: Espresso is limited to Android applications and does not support iOS or cross-platform testing. If you’re building an app for multiple platforms, you need a tool like App Percy to extend towards both Android and iOS devices.
  • No Built-In Image Comparison Engine: Espresso does not include native screenshot comparison capabilities. Developers must integrate additional libraries or tools like App Percy to perform automated UI diffing and detect rendering changes across builds.
  • Manual Baseline Maintenance: Reference images and expected states must be stored and updated manually. Without structured baseline management, maintaining visual consistency across frequent releases can become time-consuming.
  • Sensitive to Device and OS Differences: Minor variations in screen density, fonts, or system UI components can trigger differences during comparisons. Managing consistency across multiple Android versions requires careful configuration. App Percy brings a real device cloud to test within exactly these minor variations.
  • Limited Review Workflow Support: Espresso test failures appear as standard test reports without a collaborative visual dashboard. Reviewing UI changes often requires manual inspection rather than a structured approval system.
  • Scalability Depends on Infrastructure: Running tests across many devices requires external device farms or cloud infrastructure. Scaling execution efficiently is not handled natively within the framework.

Refine Your App Visuals 3x Faster

Review your app against hundreds of Android and iOS devices, run visual regression tests on parallel and resolve them instantly.

Integrating BrowserStack App Percy with Espresso for Visual Testing

BrowserStack App Percy captures screenshots during Espresso test execution, stabilizes dynamic UI elements, and performs AI-powered visual comparison tests across real devices. This transforms your existing functional UI tests into a full visual regression workflow.

Below is a simplified integration flow tailored specifically for visual testing:

Step 1: Set Up BrowserStack Credentials

Create a BrowserStack Percy account and retrieve your username and access key from the dashboard. These credentials authenticate your uploads and test executions. They are required to connect your Espresso tests with App Percy’s real device cloud.

BrowserStack Percy Credentials

Step 2: Prepare Your App and Espresso Test Suite

Generate both your Android application build (.apk or .aab) and the Espresso test suite APK. The test suite should include screenshot capture logic at key UI checkpoints to enable visual comparison during execution.

Step 3: Upload Your Application Build

Use BrowserStack’s upload API to send your Android app to the cloud. The response returns a unique app identifier. This identifier is referenced when executing visual validation runs on real devices.

Step 4: Upload the Espresso Test Suite

Upload your compiled Espresso test APK in a similar manner. This links your UI automation scripts to the uploaded app build, allowing screenshot testing to execute remotely.

Step 5: Execute Tests with Screenshot Capture Enabled

Trigger a visual test run specifying target Android devices in BrowserStack’s real device cloud. During execution, App Percy captures stabilized screenshots at defined checkpoints and stores them for baseline comparison.

Step 6: Perform Automated Visual Comparison

App Percy compares captured screenshots against approved baselines using AI-powered diffing. It intelligently filters noise from animations or rendering differences, reducing false positives in your visual comparison tests.

Step 7: Review and Approve Visual Changes

Access the App Percy dashboard to review highlighted differences. If changes are intentional, update the baseline. If not, flag regressions before release. This structured workflow ensures controlled visual validation testing at scale.

Review and Approve Changes

Switch to 10x faster mobile visual automation

App Percy leverages the biggest real device infrastructure to parallel test your mobile application across 30,000+ devices

  • AI Visual Review Agent
  • Unlimited Browser + Device Combinations
  • Visual Diff Controls
  • Intelligent Element Handling

Talk to an Expert Learn more

What are visual bugs

Conclusion

Espresso provides a reliable foundation for Android UI automation, but extending it with structured visual validation significantly strengthens quality control.

By combining Espresso’s stable interaction model with BrowserStack App Percy’s real device cloud and AI-powered visual comparison, teams can detect UI regressions early and reduce false positives.