October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Mountain View desk8 min

Getting Started with Visual UI Testing for Android Apps

Build a reliable Android UI test around one important flow, then add screenshot checks and expand across the configurations your users actually have.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start with one important Android user flow, make its data repeatable, and test both what the app does and what it looks like. Use Espresso for classic Views, Compose testing APIs for Compose screens, and add screenshot capture or comparison as a separate visual check. A screenshot alone does not prove that an interaction works or that the screen is accessible.

What visual UI testing checks

An Android UI test launches an app or part of it, performs user interactions, and checks the response. Android’s UI testing guide describes that sequence and notes that different API levels, form factors, and device customization can affect rendering or stability.

There are two complementary kinds of checks:

  • Behavior assertions verify outcomes or UI properties: for example, submitting a form displays a confirmation or an error message.
  • Visual checks capture the rendered screen and either compare it with an approved baseline or have a person review the image.

Capturing an image is not automatically a regression test. A comparison requires a reference image and a defined way to identify meaningful differences. Neither a screenshot comparison nor a successful screenshot capture establishes that the app’s controls work correctly or meet accessibility needs.

Choose a first flow and make it repeatable

Pick a high-value journey with a clear result, such as signing in, saving an item, or completing a checkout step. Keep the first test narrow: one starting state, a small number of actions, and an outcome you can assert.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Use deterministic data. Arrange a known account state and predictable responses. Prefer fake repositories or other replaceable dependencies where practical; Android’s UI testing guidance recommends an architecture that supports substituting fake dependencies.
  2. Control the starting state. Reset or seed the app’s data so a previous test run cannot change the next run’s result.
  3. Keep external services out of the critical path. If a remote response is not what the test is meant to validate, provide a stable fake response instead of relying on network timing or live data.
  4. Put instrumented tests in the Android module’s src/androidTest/java source set. These tests run against an Android device or emulator rather than as ordinary local JVM unit tests.

A useful first behavior check might assert that saving an item changes its saved state and presents the expected label. A visual check can then capture the resulting screen with the same deterministic state.

Pick the UI test framework that fits the app

Need Starting point When it fits
Interact with classic Android Views and assert results Espresso It provides UI actions and assertions and synchronizes with documented idle conditions.
Test Compose screens and components Compose UI testing APIs Use the Compose-specific APIs to launch content, find nodes, perform actions, and assert semantics.
Operate across app boundaries or interact with system UI UI Automator It works outside the target app process and can capture screenshots. The documented modern 2.4 API is under development, so check current guidance before adopting it.
Run scripted tests on a managed device matrix Firebase Test Lab It runs instrumentation tests, including Espresso or UI Automator tests, on selected virtual and physical devices and returns artifacts such as screenshots, videos, and logs.
Explore a screen without writing test code Firebase Test Lab Robo tests Robo can provide an initial exploration pass, but does not replace assertions for a critical user journey.

Espresso’s synchronization waits for the main message queue, relevant AsyncTask work, and configured idling resources to become idle. If an app uses custom asynchronous work, configure an idling resource or otherwise make the test’s wait condition explicit; a test that races the UI can produce flaky results.

Write a behavior test before adding visual comparison

Classic View apps: Espresso

Use Espresso when the screen is built with Views. A test typically launches an activity, locates a view, performs an action, and checks the result. The exact activity rule or test runner depends on the project’s AndroidX test setup, so use the dependencies and runner already configured in the app.

// Illustrative Espresso test; replace resource IDs and app setup with your own.
@Test
fun savingItemShowsSavedState() {
    onView(withId(R.id.save_button)).perform(click())
    onView(withId(R.id.saved_label)).check(matches(isDisplayed()))
}

This example demonstrates the assertion shape, not a complete project configuration: it assumes the app has a button and label with those IDs and that the test has a deterministic item loaded.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Compose apps: Compose testing APIs

For Compose UI, use its testing APIs rather than treating the composable tree as a set of ordinary Views. Tests can locate nodes through semantics, perform actions, and assert displayed text or state. Make sure the test content receives predictable dependencies and state, just as the production screen would.

// Illustrative Compose UI test; provide the actual composable and semantics in your app.
@get:Rule
val composeRule = createComposeRule()

@Test
fun savedItemIsAnnounced() {
    composeRule.setContent { ItemScreen(/* deterministic test state */) }
    composeRule.onNodeWithText("Save item").performClick()
    composeRule.onNodeWithText("Saved").assertIsDisplayed()
}

The sample is a pattern rather than a drop-in implementation: adapt the composable, labels, semantics, and setup to your screen.

Add a screenshot check and define what comparison means

Android describes screenshot testing as capturing UI and comparing the resulting image with a previously approved image. The comparison workflow you choose must support your app’s UI framework and the environment in which the test runs; verify compatibility and maintenance status before adopting a library.

  1. Run the deterministic flow at a specified device configuration and capture the relevant screen.
  2. Review and approve the initial image as the baseline. Do not approve it blindly: confirm the screen represents the expected design and state.
  3. On later runs, compare the new capture with that baseline using the chosen screenshot-testing workflow.
  4. Inspect reported differences. Update the baseline only when the visual change is intended; otherwise fix the UI or test setup.

For raw captures rather than automated baseline comparison, modern UI Automator can capture a full screen, window, or element and attach artifacts to Android Studio test results. That is useful for examining a failure, but does not by itself perform a baseline comparison.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Visual differences can arise from fonts, animation, system bars, time-dependent content, or configuration changes. Stabilize these inputs where possible, capture at a known state, and avoid treating every pixel difference as a product defect without review.

Expand coverage around the audience, not every permutation

Android recommends considering API level, locale, and orientation, as well as tablets, foldables, and other form factors in addition to phones. Firebase Test Lab identifies devices using characteristics including model, OS version, orientation, and locale. Prioritize combinations that represent your actual users and likely risk rather than running every possible combination.

  • API level: include supported Android versions where behavior or rendering may differ.
  • Locale: check languages and text expansion relevant to your audience.
  • Orientation: test portrait and landscape if the app supports both or relies on responsive layout.
  • Form factor: include tablets or foldables when those devices are in scope; a phone-only layout may not expose their issues.
  • Hardware: use a physical device when a flow depends on real hardware behavior. Firebase notes that physical-device runs may reveal issues not seen on Android Studio emulators.

Use a local emulator or device while developing, then select managed device configurations when broader coverage is needed. Firebase Test Lab accepts scripted instrumentation tests and also offers Robo exploration. Its documentation states maximum test durations of 45 minutes on physical devices and 60 minutes on virtual devices; check the current Firebase documentation for plan, quota, and billing details before scheduling runs.

Capture Firebase Test Lab screenshots when you need artifacts

Firebase’s instrumentation screenshot guidance uses AndroidX ScreenCapture with testlab-instr-lib for screenshots attached to Test Lab results. Follow the current Firebase instrumentation test guide for dependency and implementation details because setup can change. That guide says to omit WRITE_EXTERNAL_STORAGE on Android 10 / API 29 and later; do not add the permission by habit on newer Android versions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the Firebase console or supported command-line workflow to select devices and run the instrumentation package, then inspect the returned logs and artifacts alongside assertion failures. Console projects require the Blaze pay-as-you-go plan linked to Cloud Billing according to Firebase’s Get Started guidance; verify current pricing, quotas, and billing requirements at Firebase Test Lab before running a matrix.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Run locally, then diagnose failures systematically

Local feedback loop

  1. Run the instrumented test on an emulator or connected device from Android Studio.
  2. Confirm the behavior assertions pass with repeatable test data.
  3. Capture or compare the screenshot only after the app reaches the intended state.
  4. When a failure occurs, inspect the assertion output, screenshot, logcat, and any available video before changing the baseline.
  5. Move representative tests to a selected Test Lab matrix when local coverage is not enough.

Common problems and fixes

  • Flaky timing or element-not-found failures: the screen may still be loading or background work may not be represented by Espresso’s synchronization. Use a deterministic response and configure an idling resource or explicit wait condition rather than adding arbitrary long sleeps.
  • Different screenshot on each run: remove variable inputs such as changing test data, transient animations, or uncontrolled time-dependent content; ensure the same state and configuration are used for the baseline and comparison.
  • Screenshot exists but no regression is reported: capture alone is not comparison. Add a baseline-based screenshot-testing workflow or explicitly review the images manually.
  • Works in emulator but fails on hardware: inspect device-specific behavior and artifacts, then include representative physical devices when hardware matters.
  • Firebase run cannot start or incurs unexpected cost: check the current project billing linkage, quotas, selected device configuration, and Firebase pricing documentation before retrying.
  • Permission-related screenshot setup fails: follow the current Firebase setup guide; its instructions say not to include WRITE_EXTERNAL_STORAGE on API 29 and later.

Or skip the browser setup

For a web page screenshot used in a report or web-based visual check, ScreenshotNeo offers a one-request screenshot API. This is separate from Android instrumentation: it captures a URL in a browser, not a native Android app screen. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for ScreenshotNeo.

Frequently Asked Questions

Can I use Robolectric for Android UI testing?

Yes, when a JVM-run UI test suits the behavior you need to exercise; use an emulator, device, or managed device run when the test depends on Android runtime or device configurations.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does Firebase Test Lab replace local UI testing?

No. Local runs provide a quick development loop; Test Lab adds selected virtual and physical device configurations and result artifacts.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.