Flaky Espresso tests in 2026: fix them before a major release

Flaky Espresso tests triaged before a 2026 major release: causes, fixes and team workflow

TL;DR

Flaky Espresso tests in 2026 still come from one place: the test acts before the app is ready. In the most cited study, async waits made up 45% of classified flaky-test fixes. Before a major release, the order of work matters more than any single fix.

  • Triage first: rerun each red test alone, then in a loop, and split flaky from broken.
  • Replace sleeps with idling resources or wait-until conditions.
  • Isolate state with Android Test Orchestrator, turn off animations and pin your devices.
  • Quarantine what you cannot fix in time, with an owner and a date, and retry only big tests.
  • Since August 31, 2026, Google Play requires API level 36, which changes back navigation and layouts your tests assert on.

Why Espresso end-to-end tests turn flaky

A flaky test passes and fails on the same code. At Google scale that is a measured cost. John Micco's post on the Google Testing Blog reported that about 1.5% of all test runs came back flaky and almost 16% of tests showed some flakiness.

The causes are well studied. Luo and colleagues classified flaky-test fixes from 51 open-source projects: async waits made up 45%, concurrency 20% and test order dependency 12%. A study of UI-based flaky tests by Romano and colleagues found async waits behind 45.1% of 235 flaky UI tests, and platform issues twice as often on Android as on the web, 21.7% against 10.5%. A study of Android projects by Thorve and colleagues put concurrency first, at 36% of 77 flaky-test commits.

Google's guide to big test stability calls synchronization gaps "a primary source of flakiness" and adds: "As a test grows in scope, it increases the chances of becoming flaky." A travel booking flow is as big as Android tests get, with every screen waiting on the network.

Vendors that test the whole booking, from the traveler's phone to the operator side, are ranked in our list of mobile app testing companies.

Since August 2026, API level 36 changes what your tests see

Since August 31, 2026, Google Play requires new apps and app updates to target Android 16, API level 36. Extensions ran to November 1, 2026. Three Android 16 behavior changes land on UI tests:

  • Edge-to-edge is enforced on Android 16 devices, so layouts shift under the system bars.
  • Predictive back is on by default. onBackPressed is not called, so tests that rely on an overridden onBackPressed stop passing.
  • On displays 600dp and wider, orientation locks are ignored. Google warns of more activity re-creation, which a portrait-only tablet test never met.

The device farm is moving too. Firebase Test Lab's CLI documentation says the service will be fully shut down on September 30, 2027, with Developer Device Platform as the replacement. Its flag translation guide turns --num-flaky-test-attempts=2 into --flaky-test-attempts=3, because the new flag counts total attempts. Plan that migration outside the release window.

How we built this playbook

We read what ranks for this question. Drizz's How to Fix Flaky Mobile Tests covers four root causes and a CI workflow. No page we read covered an Espresso suite in a travel booking product, or how an outside QA team splits the work with the client's engineers.

Platform guidance comes from documentation read in November 2026, research numbers from the papers, engagement patterns from Mercury's QA records without client names. Mercury sells QA services: read the last two sections as an interested view.

Flaky Espresso failures at a glance

CauseWhat you see in EspressoFirst fixWho owns it
Background workNoMatchingViewException on a view that appears a moment laterIdling resource or wait-until conditionApp team
AnimationsA tap registers as a long press on a slow deviceTurn off animation scalesTest infrastructure
Shared statePasses alone, fails in the suiteTest Orchestrator with clearPackageDataTest infrastructure
Device interruptionsA system dialog covers the appManaged or pinned devicesDevice lab owner
Test dataAn account expired or inventory sold outSeeded or mocked data per testBackend team
Real race in the appRare failure users can also hitFix the app codeFeature team

Triage: separate flaky from broken in a day

Before a release, the red list mixes flaky tests with real regressions. Sort it before anyone fixes anything.

  1. Rerun every red test alone on a clean device. A test that fails alone is broken or has found a bug.
  2. Loop the rest. Yelp's Android team ran each new or changed test 20 times and rejected it on a single failure. On iOS, Xcode's test repetitions do the same with run-tests-until-failure.
  3. Tag each flaky test with a cause from the table, from logs and screen recordings.
  4. Rank by release risk. A flaky test on booking confirmation outranks one on a settings screen.

The output is one list with an owner per line.

Fix synchronization first

Async waits lead both of the larger studies above, so they get the first fixes.

Espresso tracks the main thread. Background work has to report itself. Android's idling resources guide lists data loading, database connections and services as the usual suspects. CountingIdlingResource counts active tasks and is usually enough. UriIdlingResource waits for a quiet period, which suits back-to-back calls such as an availability check followed by a price check.

The same guide calls Thread.sleep(), retry loops and CountDownLatch bad workarounds. For the biggest tests, Google prefers waiting for a condition, such as a text appearing.

Register idling resources before the first Espresso action: synchronization starts only after Espresso's first idle check.

Remove shared state and order dependence

A test that passes alone and fails in the suite reads something an earlier test left behind. A logged-in session, a cached search, a draft booking.

Android Test Orchestrator runs each test in its own Instrumentation invocation, so one crash no longer ends the run. With clearPackageData set to true, it runs pm clear after each test. The cost is time, because the app restarts after every test. Before a release, clean results are worth it.

Test data is the other half. Each test creates the reservation it needs or reads it from a mock, because shared staging accounts expire mid-sprint.

Make the test device boring

Espresso's setup guide highly recommends turning off three system animations: window animation scale, transition animation scale and animator duration scale. The Android Gradle plugin's animationsDisabled option does it for command-line runs, which is where CI lives.

Gradle managed devices define the emulator in the build and retry lost connections. Google's stability guide adds system update dialogs and low disk space to the interruptions to rule out. On a physical lab, freeze OS versions until the release ships. After the API 36 change, add one device 600dp or wider.

Some failures appear only on the hardware and network of a real ship. Our guide to cruise ship app testing covers that test window.

Quarantine with an owner and an expiry date

Some tests will not be fixed before the release date. Quarantine them, out loud.

Yelp's setup is a good model. Every Android test had an owning team, and a broken or flaky test on master was suppressed automatically, with a ticket for that team. Before the change, master passed only about 60% of the time. Afterward, master tests succeeded 87% of the time over two weeks, and UI tests 93%.

Add two rules for the release. Every quarantined test gets a return date. Every one on a booking or payment path gets a manual check in the release checklist until it comes back.

Retries: where they belong and what they hide

Google's guidance fits in one line: "Add retrying mechanisms to big tests, but always fix flaky tests." Retry lost emulator connections and big end-to-end flows, through a JUnit rule or a CI step.

Then count the retries. A test that passes on its second attempt every night is flaky, and a rising retry count is your earliest warning.

Never retry a test that guards a race users can hit. If a double tap on Book creates two reservations in one run out of fifty, the retry hides a production bug.

Working with the client's iOS and Android teams

Outside help on a flaky suite fails when it arrives as a parallel team with its own tools.

  • Use the client's tooling. If the Android team standardized on Espresso, fixes land in Espresso, in their repository, through their code review.
  • Get one named lead per platform on the client side. Android and iOS suites fail for different reasons.
  • Keep one triage list for both platforms, ranked by the product owner who already directs the work.
  • Agree what done means for a flaky test: fixed, quarantined with an owner, or deleted with a reason.
  • Settle repository access, device lab access and the purchase order before the clock starts. The release date does not move.

If you are choosing an outside team for this work, our ranking of QA testing outsourcing companies compares seven vendors.

What our mobile QA engagements show

Mercury's QA practice has 100+ QA engineers who embed in the client's team and use the client's tools. Our test automation page lists Kotlin, Java and Appium, but not Espresso. On Android engagements we work in what the client's team already runs.

Our records from mobile QA work for a bookable-travel marketplace client follow the pattern in this guide. The client had separate Android and iOS test leads, kept Espresso as its standard Android tooling and wanted flaky end-to-end tests fixed fast ahead of a fixed major release date. Direction came from the client's product owner, and ramp-up waited on the purchase order.

The structure repeats outside travel. Tonal came to Mercury with existing iOS and Android apps, and the case page describes integrating the external team deeply into Tonal's processes, quality assurance included.

Our take: a flaky test is a bug report

A flaky test is a bug report with a bad reproduction rate. Sometimes the bug is in the test. Sometimes it is in the app, and the test is the only witness.

Before a major release, do not aim for a green suite. Aim for an explained one, where every red or quarantined test has a cause, an owner and a date. Green bought with retries and sleeps moves the failure from your CI to your travelers' phones in launch week.

Written by Rob Devereaux, Chief Operating Officer at Mercury Development. Rob has run the firm's operations from Hudson, Ohio since 2019 and has over 20 years of operational and financial experience.

Major release on the calendar and a red Android suite? Start with triage

Tell us your release date, how your Espresso and iOS suites run today and where they fail. We will come back with a triage plan: which tests to fix first, which to quarantine and who on your team owns each one.

Plan the triage of your Espresso suite.

Feel free to contact us and we'll respond as soon as possible.

Frequently asked questions

Sources

  1. Micco, J. Flaky Tests at Google and How We Mitigate Them. Published 2016-05-27. (BlogPosting)
  2. Luo, Q. An Empirical Analysis of Flaky Tests. Published 2014. (ScholarlyArticle)
  3. Romano, A. An Empirical Analysis of UI-based Flaky Tests. Published 2021. (ScholarlyArticle)
  4. Thorve, S. An Empirical Study of Flaky Tests in Android Apps. Published 2018. (ScholarlyArticle)
  5. Google. Big test stability. Undated. (TechArticle)
  6. Google. Meet Google Play's target API level requirement. Undated. (TechArticle)
  7. Google. Behavior changes: Apps targeting Android 16 or higher. Undated. (TechArticle)
  8. Google. Start testing with the gcloud CLI. Undated. (TechArticle)
  9. Google Cloud. Firebase Test Lab to Developer Device Platform Command and Flag Translation. Undated. (TechArticle)
  10. Abrar, A. How to Fix Flaky Mobile Tests. Undated. (BlogPosting)
  11. Rosen, S. Auto-suppressing Tests for More Reliable Code in our Android App. Published 2017-08-24. (BlogPosting)
  12. Apple. Diagnose unreliable code with test repetitions. Published 2021. (WebPage)
  13. Google. Espresso idling resources. Undated. (TechArticle)
  14. Google. AndroidJUnitRunner. Undated. (TechArticle)
  15. Google. Espresso setup instructions. Undated. (TechArticle)
  16. Google. TestOptions - Android Plugin 3.4.0-dev DSL Reference. Undated. (TechArticle)
  17. Mercury Development. Quality Assurance & Software Testing Services. Undated. (WebPage)
  18. Mercury Development. QA Test Automation. Undated. (WebPage)
  19. Mercury Development. Tonal Case Study: Branding, Web Design, and Development. Undated. (WebPage)
  20. Mercury Development. Internal mobile QA engagement records, aggregated. Undated. (Dataset)