Which UI Tests Belong on Emulators and Simulators, and Which Stay on Real Devices
AWS Device Farm now runs Android emulators and iOS simulators next to real devices. The announcement is clear about where it expects you to use them: virtual devices for "stages that need high speed and volume, such as pull requests, code merges, and smoke tests", real devices for "later stages that need high fidelity", meaning regression and release testing.
What the announcement can't do is make a test less flaky. A test that sleeps two seconds and hopes will sleep two seconds and hope on a virtual device.
I read the announcement and the Device Farm developer guide.
Startup time: the announcement says virtual devices on the latest OS "typically start in seconds" and others in around a minute. The developer guide is more precise. The latest OS is usually ready in under 30 seconds, other versions in about a minute.
Price: the announcement says virtual devices use "the existing metered pricing". The pricing page lists $0.17 per device minute, with a one-time trial of 1,000 minutes, and an unmetered plan from $250 per slot per month. I found no separate virtual device rate there, so check the console. Android unmetered slots now cover emulators. iOS simulators are metered only, and the guide says an unmetered request for one is rejected with an error.
Limits worth knowing: default metered concurrency is five devices, and simulator jobs count against it. A device pool or a run can't mix virtual and physical devices. An automated run stops at 150 minutes. Virtual devices don't support VPC endpoint connectivity, and you can't set Android system properties on emulators.
Setup: Android emulators run only on the amazon_linux_2023 test host. iOS simulators need a simulator build (arm64, no code signing) and the macos_tahoe test host.
Test frameworks: Instrumentation and Appium on Android, XCTest, XCTest UI and Appium on iOS. Detox and Flutter's integration_test are not on that list.
Supported OS versions: the developer guide says emulators run Android 15, 16 and 17, and since they're 64 bit x86_64 devices, any native libraries need an x86_64 build. iOS simulator versions are only listed in the console, which I couldn't open.
The docs disagree with each other in two places. The announcement promises the same "private endpoint access" for virtual and real devices, while the guide says virtual devices don't support VPC endpoints. If your staging backend is private, believe the guide and test it early. And the Device Farm FAQ still says tests run on real devices, so that page is behind.
Here's what I'd check first before a move: that console list, and whether your staging backend needs a VPC endpoint.
Apple's session on test repetitions lists the causes of unreliable tests as "race conditions, environment assumptions, global state, or communication with external services". None of the docs I read publish a share of failures per cause, so any claim that most flakes come from test design is my judgment, and I measured nothing.
Waits come first. Espresso's guide names three workarounds that it calls bad: Thread.sleep(), retry wrappers and CountDownLatch. Of the first it says your tests "might still fail sometimes when executed on slower devices". A fixed delay tuned on your laptop is a guess about somebody else's CPU, and a cloud pool changes that CPU without telling the test.
Animations are the second source. The Espresso setup page says "To avoid flakiness, we highly recommend that you turn off system animations on the virtual or physical devices used for testing", and lists the three system animation scales. The Android Gradle plugin can turn animations off for command line instrumented runs through testOptions.animationsDisabled. AGP 9.5.3 does not do that by adding --no-window-animation to the am instrument command. Device Farm's Instrumentation page says it turns the three scales off itself when you use AndroidJUnitRunner. That page doesn't mention emulators, so confirm it on a virtual device.
Shared state and test order cause the failures that pass alone and break in the suite. Android Test Orchestrator runs each test in its own Instrumentation instance, and its clearPackageData flag clears the app's data between tests. On Apple's side, a test plan's Execution Order setting can pick a random order each time, which Apple says can uncover tests that depend on actions taken in other tests.
The network is the last one. Android's testing strategy page lists mocked network access for feature tests, and brings in staging or production servers at the application and release candidate levels. For a pull request check, that means a fake server or fakes in the app instead of a live backend. Detox waits for in-flight requests, but it can't make a slow server fast.
Espresso synchronizes only what posts to the main thread's message queue. The idling resource guide says so directly: "Espresso isn't aware of any other asynchronous operations, including those running on a background thread." Anything on a background thread that changes the UI needs an idling resource. The guide says CountingIdlingResource is enough in most cases, recommends keeping the idling logic in the app and only registering it from tests, and asks you to unregister when you're done.
// App side: wrap the background work
object LoadingIdler {
val resource = CountingIdlingResource("repository-load")
}
suspend fun loadItems(): List<Item> {
LoadingIdler.resource.increment()
try {
return api.fetchItems()
} finally {
LoadingIdler.resource.decrement()
}
}
// Test side: register before the test needs it
@Before fun registerIdler() {
IdlingRegistry.getInstance().register(LoadingIdler.resource)
}
@After fun unregisterIdler() {
IdlingRegistry.getInstance().unregister(LoadingIdler.resource)
}
The app module needs implementation("androidx.test.espresso:espresso-idling-resource:3.7.0") for CountingIdlingResource.
Compose tests are "synchronized by default with your UI", on a virtual clock, so they usually don't need this. The edge cases are work outside Compose and animations. For work outside Compose, the docs say to use waitUntil, and they warn that a CountDownLatch can behave unexpectedly because the test clock doesn't advance. For animations, turn autoAdvance off and step the clock yourself.
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Test
fun itemsAppearAfterLoad() {
composeTestRule.onNodeWithText("Load").performClick()
composeTestRule.waitUntilAtLeastOneExists(hasTestTag("item-0"), 5_000)
composeTestRule.onNodeWithTag("item-0").assertIsDisplayed()
}
@Test
fun detailsExpandAfterAnimation() {
composeTestRule.mainClock.autoAdvance = false
composeTestRule.onNodeWithText("Expand").performClick()
composeTestRule.mainClock.advanceTimeBy(300)
composeTestRule.onNodeWithTag("details").assertIsDisplayed()
}
The second test controls time, so a fast emulator and a slow one behave the same. The first returns as soon as the node exists, with a five-second ceiling.
Then switch on the isolation and animation settings once, in Gradle, so every virtual device behaves the same way.
// module build.gradle.kts
android {
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}
testOptions {
animationsDisabled = true
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
dependencies {
androidTestImplementation("androidx.test:runner:1.7.0")
androidTestUtil("androidx.test:orchestrator:1.6.1")
}
The orchestrator docs note one cost: each test restarts the app, so total time can go up. On a suite with shared-state flakes, I'd take that trade.
Here's what I'd check on a flake first: a Thread.sleep() left in the test, or a background load with no idling resource. Shared app state that leaks from the previous test is the other common one, and the orchestrator is the usual fix for that.
waitForExistence(timeout:) waits for an element and returns false if the timeout expires, so the assertion is on you. For something that should disappear, use an XCTNSPredicateExpectation with a predicate such as exists == false, then wait(for:timeout:). XCTestCase reports a timeout as a failure on its own, which keeps the test from hanging quietly. Apple's docs: waitForExistence(timeout:), XCTNSPredicateExpectation and wait(for:timeout:).
You can pass a launch argument such as -uitesting through XCUIApplication.launchArguments. What the app does with it, such as swapping in a fake backend, is your design.
To find out whether a test is flaky, run it many times. Xcode 13 added test repetition with three modes: fixed iterations, until failure, and retry on failure. Apple's WWDC21 session, Diagnose unreliable code with test repetitions, warns that "retrying failures can hide problems in the actual product", and says "it's best to use this mode temporarily to diagnose the failures". My position is that retry on failure in a pull request pipeline is a bandage that you should date and remove. On the command line, the same session says xcodebuild flags override the test plan. Pass -test-iterations with a number, and combine it with -run-tests-until-failure to stop at the first failure.
Use the repetition result as your evidence. A test that fails some of its 100 runs on a simulator on your Mac has a design problem you can fix. A test that passes all 100 there and fails in the cloud points at the environment, and you can only learn that once the first number is clean.
Here's what I'd check on an XCUITest flake that is already failing some of those runs: a system alert the test doesn't handle, or an animation or a network call that the test never waits for.
Flutter. The integration_test package lets you use flutter drive to run tests on a physical device or an emulator, and run them on Firebase Test Lab. Most of the waiting problems show up in pumpAndSettle(). It pumps frames until none are scheduled, which the docs describe as essentially waiting for all animations to finish. If something animates forever, such as an indeterminate progress indicator, it throws after its timeout (ten minutes by default). The API docs call it "better practice to figure out exactly why each frame is needed, and then to pump exactly as many frames as necessary." Use pumpAndSettle() for short, finite transitions, and pump a known duration when a spinner is on-screen.
React Native. The React Native testing overview says end-to-end tests give the highest confidence, are "more prone to flakiness" than other types, and names Detox, Appium and Maestro as options. Detox is a gray-box tool, and its docs say it monitors network requests, the main thread, layout, timers, animations, the React Native JavaScript thread and the bridge, then "proceeds to the next action in the test code only after the app is stable". That removes many manual waits. The cost is strictness: by default Detox fails the test if timers or animations never finish, and the synchronization debugging logs show you which task kept the app busy. Fix the endless loader instead of turning synchronization off.
Android's testing strategies page puts feature tests on local runs and emulators before merge, application tests on emulators and one phone and one foldable after merge, and release candidate tests on eight phones, a foldable and a tablet before release. The page says these guidelines "don't need to be followed strictly", and that tests can move for reasons such as "infrastructure cost, flakiness, and long test times". The Android Emulator page is even more direct: "In most cases, the emulator is the best option for your testing needs."
So here is the split I'd start from.
Run on emulators and simulators as pull request and merge checks: navigation and screen flows with a faked backend, form validation, state restoration after rotation and process death, accessibility labels, layout across screen sizes and API levels, deep links, notification payload handling. Android's CI page says a more advanced setup can test across environments such as API levels and screen sizes.
Keep on real devices. Where I have a source, I quote it. The rest is my judgment:
- Camera. Apple says that when you run an app in a simulator, "some hardware-specific features might not be available", and to test the feature itself on a physical device. The Android Emulator's camera shows a simulated scene you can load pictures into, and Android's strategy page says camera apps "might depend on specific hardware features". Even Device Farm's real devices note that photos "might look dark and blurry" because of how they are mounted, so capture quality is a hands-on check.
- Biometrics. The emulator can simulate 10 different fingerprint scans, so I'd keep the prompt flow and error handling in the virtual run. In my judgment, the sensor itself, and anything specific to a vendor's face or fingerprint hardware, still belongs on a real device. The docs I read don't describe that difference.
- Push. The picture has changed. Xcode 14's release notes say Simulator supports remote notifications from iOS 16, through the APNs sandbox, on Apple Silicon or T2 Macs, and the Firebase docs support an emulator running Android 7.0 with Google APIs. That covers registration, payload handling and tap routing. In my judgment, I'd still send a production push to a real device before a release. I can't confirm that a virtual device exercises the production path, or each vendor's battery management.
- OEM quirks. Device Farm describes its real devices as "a variety of OEMs". Android's docs don't catalog vendor-specific behavior, so I can't cite one. It is the main reason a release candidate matrix of real phones exists.
- Performance. Android's Macrobenchmark guide says "We discourage running the benchmarks on an emulator, as they don't produce performance numbers representative of the end-user experience." Apple says simulators "don't replicate the performance or features of a physical device".
- Low-end hardware. An emulator or simulator runs on the host's CPU and memory, so its speed tells you about the host. In my judgment, if you care how the app behaves on a low-end phone, you still need a low-end phone.
Here's what I'd do when a failure shows up on only one model or one OEM skin: treat it as a real-device case and add that model to the release matrix, rather than chasing it on an emulator.
For the Android side, Gradle Managed Devices lets you declare emulators in the build. A device group runs the tests across all of its devices, and it's also how I'd build an API level matrix.
// module build.gradle.kts
android {
testOptions {
managedDevices {
localDevices {
create("pixel2api30") {
device = "Pixel 2"
apiLevel = 30
systemImageSource = "aosp"
}
create("pixel2api34") {
device = "Pixel 2"
apiLevel = 34
systemImageSource = "aosp"
}
}
groups {
create("ciPhones") {
targetDevices.add(allDevices["pixel2api30"])
targetDevices.add(allDevices["pixel2api34"])
}
}
}
}
}
Run one device with ./gradlew pixel2api30DebugAndroidTest or the whole group with ./gradlew ciPhonesGroupDebugAndroidTest. Use allDevices, not devices. The Android page still shows devices["..."], which does not compile on AGP 9. On servers without hardware rendering, such as GitHub Actions, pass -Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect.
Gradle Managed Devices gives you control of the image, and you provide the machines. Device Farm gives you managed capacity and one API for real and virtual devices, as long as your build fits the limits from section 1.
Run this before you move a flaky test anywhere.
- Run the test alone, 100 times, on one virtual device. On iOS use
-test-iterationswith-run-tests-until-failure. If it never fails, look at the suite or the environment. - Read the failure. A timeout points at a wait. A "not found" right after a tap points at a missing synchronization.
- Search the test for
Thread.sleep,sleep,CountDownLatchand fixeddelaycalls. Replace each with a condition: an idling resource,waitUntil,waitForExistenceor an expectation. - Run the whole suite in random order. On Android use the orchestrator with
clearPackageData. On iOS set Execution Order to random in the test plan. - Turn off animations, then look for ones that never end. A spinner that runs forever will fail
pumpAndSettle()and Detox's idle check. - Replace the live backend with a fake for pull request runs.
- If it fails only on one device model, one API level or one OEM, stop tuning it. That test belongs in your real device pool.
- Don't turn on retry as the fix. If you must use it, write down the date and remove it.
Moving a clean, fast set of tests to virtual devices makes sense, and AWS now gives you a managed place to do it. Moving a flaky set there makes the failures more expensive to reproduce. Fix the waits first, repeat the test until you trust it, then decide which tests earn a place on real hardware.
Sources
All pages opened on 26 November 2026.
AWS
- AWS Device Farm now supports Android emulators and iOS simulators (25 Nov 2026): https://aws.amazon.com/about-aws/whats-new/2026/11/device-farm-virtual-devices/
- Testing on virtual devices in Device Farm: https://docs.aws.amazon.com/devicefarm/latest/developerguide/virtual-devices.html
- Device support in AWS Device Farm: https://docs.aws.amazon.com/devicefarm/latest/developerguide/devices.html
- Purchasing a device slot in Device Farm: https://docs.aws.amazon.com/devicefarm/latest/developerguide/how-to-purchase-device-slots.html
- Limits in AWS Device Farm: https://docs.aws.amazon.com/devicefarm/latest/developerguide/limits.html
- Test environment for Android devices: https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environments-hosts-android.html
- Test environment for iOS devices: https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environments-hosts-ios.html
- Test frameworks and built-in tests: https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types.html
- Apps in AWS Device Farm: https://docs.aws.amazon.com/devicefarm/latest/developerguide/apps.html
- Instrumentation tests in Device Farm: https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-instrumentation.html
- AWS Device Farm pricing: https://aws.amazon.com/device-farm/pricing/
- AWS Device Farm FAQs: https://aws.amazon.com/device-farm/faqs/
Android
- Espresso idling resources: https://developer.android.com/training/testing/espresso/idling-resource
- Espresso setup instructions: https://developer.android.com/training/testing/espresso/setup
- Synchronize your tests (Compose): https://developer.android.com/develop/ui/compose/testing/synchronization
- Android Test Orchestrator (AndroidJUnitRunner): https://developer.android.com/training/testing/instrumented-tests/androidx-test-libraries/runner
- Scale your tests with build-managed devices: https://developer.android.com/studio/test/managed-devices
- TestOptions, Android Gradle plugin API reference: https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/dsl/TestOptions
- Testing strategies: https://developer.android.com/training/testing/fundamentals/strategies
- Continuous Integration basics: https://developer.android.com/training/testing/continuous-integration
- Run apps on the Android Emulator: https://developer.android.com/studio/run/emulator
- Emulator extended controls: https://developer.android.com/studio/run/emulator-extended-controls
- Macrobenchmark overview: https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview
- Firebase Cloud Messaging, Android client: https://firebase.google.com/docs/cloud-messaging/android/get-started
Apple
- Running your app on simulated or physical devices: https://developer.apple.com/documentation/xcode/running-your-app-on-simulated-or-physical-devices
- Organizing tests into test plans: https://developer.apple.com/documentation/xcode/organizing-tests-to-improve-feedback
- Diagnose unreliable code with test repetitions, WWDC21: https://developer.apple.com/videos/play/wwdc2021/10296/
- Xcode 14 release notes: https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
- waitForExistence(timeout:): https://developer.apple.com/documentation/xcuiautomation/xcuielement/waitforexistence(timeout:)
- wait(for:timeout:): https://developer.apple.com/documentation/xctest/xctestcase/wait(for:timeout:)
- XCTNSPredicateExpectation: https://developer.apple.com/documentation/xctest/xctnspredicateexpectation
- XCTWaiter: https://developer.apple.com/documentation/xctest/xctwaiter
- launchArguments: https://developer.apple.com/documentation/xcuiautomation/xcuiapplication/launcharguments
Flutter, React Native, Detox
- Flutter integration tests: https://docs.flutter.dev/testing/integration-tests
- WidgetTester.pumpAndSettle: https://api.flutter.dev/flutter/flutter_test/WidgetTester/pumpAndSettle.html
- React Native testing overview: https://reactnative.dev/docs/testing-overview
- How Detox works: https://wix.github.io/Detox/docs/articles/how-detox-works
- Detox, dealing with synchronization issues: https://wix.github.io/Detox/docs/troubleshooting/synchronization






Top comments (1)
Quit informative