iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
How do I test an Android app? Start with fast local JVM tests for business logic, then add instrumented tests on an emulator or physical device for Android framework behavior and user-facing flows. Put local tests in module/src/test/java/ and device tests in module/src/androidTest/java/. Choose Compose testing APIs for Jetpack Compose screens and Espresso for View-based screens; use Robolectric only where its Android simulation is good enough. This layered approach gives quick feedback without pretending that one test type can prove everything.
The right first plan depends on three facts about your project: whether the UI uses Compose or Views, whether the code under test calls Android APIs, and which build and test dependencies are already in place. The steps below turn those choices into a maintainable test suite.
What Android testing actually covers
Testing is not a choice between “unit tests” and “instrumented tests.” Those labels describe where code executes. A local test runs on a developer machine or CI server, normally on the JVM. An instrumented test runs with Android instrumentation on a physical device or emulator. Your strategy also has a scope: a function, a component, a feature, the whole application, or a release candidate.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
| Option | Best fit | Main trade-off |
|---|---|---|
| Local JVM test | Isolated business logic with Android dependencies replaced by fakes | Fast and simple, but it does not exercise the full Android runtime |
| Instrumented device or emulator test | Framework integration, functional UI flows, and runtime behavior | More realistic execution, but it needs a device or emulator and produces a separate test APK |
| Robolectric local test | Selected Android-dependent tests where a JVM simulation is adequate | Avoids emulator overhead, but support and visual fidelity are incomplete for some APIs and system interactions |
| Screenshot test | Visual regression checks across components or window sizes | Requires approved baselines and a rendering environment with suitable fidelity |
| Compose testing APIs or Espresso | Compose semantics and interactions, or View-based UI interactions | The interface technology determines the primary framework; hybrid screens may need both |
Android’s testing guidance also distinguishes test scope by fidelity, speed, isolation, network access, build type, and when a test runs. A release-candidate test exercises a minified, optimized release build in an environment close to production. An application test commonly exercises a debuggable build. Neither category replaces focused tests lower in the stack.
#1 Best Overall
- YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
- LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
- MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
- NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
- BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.
How do I choose a first Android testing plan?
Use this order rather than trying to automate every screen immediately.
1. Map code to behavior
List the behavior that can fail independently of Android: ViewModel or presenter state transitions, repository and data transformations, domain use cases, validation, parsing, formatting, and utility functions. Mark code that touches a database, network client, file system, lifecycle, permissions, system UI, or other Android API. The first group is usually local-test material; the second group needs either a replaceable dependency, a suitable simulator, or a real Android runtime.
2. Start with high-value paths and boundaries
For each unit, write a normal-case test and tests for boundaries that matter to users. Examples include malformed data, an empty response, a connection failure, retry behavior, and a state change while an activity is recreated. Do not invent a universal test-percentage target. Add coverage where a failure would block a user, corrupt data, or prevent the app from starting.
3. Select the runtime by fidelity
If a fake repository lets a ViewModel run without Android, keep that test local. If the behavior depends on framework scheduling, an Android database, WebView, system UI, or exact rendering, run it on an emulator or device. Robolectric can be a useful middle layer for selected Android APIs, but it is not a blanket substitute for device testing.
4. Add UI checks for user-visible outcomes
Test the action a user takes and the result they can observe. For example, tap Continue and assert that Welcome is displayed. The assertion should describe the outcome, not merely prove that a test-framework method was called.
Where do Android tests live?
Android Gradle projects normally have two relevant source sets:
Rank #2
- Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
- DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
- CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
- PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
- BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.
module-name/src/test/java/contains local JVM tests.module-name/src/androidTest/java/contains instrumented tests for a device or emulator.
The same convention applies when your source language is Kotlin; the directory name may be kotlin in projects configured that way. Keep a test beside the module whose behavior it verifies, rather than putting all tests in the application module by habit.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Instrumented tests are packaged into a separate test APK. They receive instrumentation APIs and an app context, which is why they can interact with Android components that a plain JVM test cannot. In Android Studio, right-click a class or method, choose the command to create a test, and select the destination source set. The IDE creates the package and a starter method; you still need to define a meaningful behavior and assertion.
How do I write my first Android unit test?
Assume a ViewModel asks a repository for a greeting and exposes a state. Keep the repository behind an interface so the test can supply a deterministic fake.
interface GreetingRepository {
fun greeting(): String
}
class GreetingViewModel(
private val repository: GreetingRepository
) {
fun message(): String = repository.greeting()
}
A local test can now run without an Android device:
class GreetingViewModelTest {
@Test
fun message_uses_repository_greeting() {
val fake = object : GreetingRepository {
override fun greeting() = "Welcome"
}
val viewModel = GreetingViewModel(fake)
assertEquals("Welcome", viewModel.message())
}
}
The exact assertion library can vary with the project. The important properties are isolation, repeatability, and a failure message that explains the expected behavior. Avoid a test that calls the production service, depends on current time, or waits for an uncontrolled network response.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use test doubles deliberately
A fake is a small working replacement, such as an in-memory repository. A stub returns a value for a particular call. A mock verifies interactions. For beginner tests, a fake or stub often makes the behavior clearer than asserting every internal call. Replace clocks, random-number generators, network clients, databases, and file stores when their variability is irrelevant to the behavior under test.
Rank #3
- YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
- LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
- MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
- NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
- BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.
Cover state and failure transitions
If a ViewModel exposes loading, success, and error states, test each transition and the inputs that trigger it. Include a failed connection, malformed payload, empty result, and recreation-related state where those cases are part of the contract. Keep framework entry points thin. Android’s guidance is that activities, fragments, and services should not own business logic; test their integration and user-visible behavior with instrumented or UI tests instead of trying to unit-test Android’s own implementation.
What is the difference between local and instrumented tests?
A local test starts in the JVM on your workstation or CI server. It is usually the quickest way to check pure Kotlin or Java behavior and is easy to run on every change. It does not, by itself, prove that Android lifecycle callbacks, resources, permissions, window management, or a real database behave correctly.
An instrumented test is installed with your app on a physical Android device or emulator. It can use instrumentation APIs, app context, Android resources, and the runtime behavior of the platform image. The cost is setup time, device availability, slower execution, and a separate test APK. A device test is therefore valuable when fidelity matters, not as a replacement for every fast unit test.
Free tools Windows power users keep installed
One-click scans. No signup required.
Do I need an emulator to test an Android app?
No. You can run local JVM tests without an emulator. You do need an emulator or physical device for instrumented tests that rely on Android runtime behavior. A connected device is often useful for a final smoke pass, while an emulator gives repeatable API levels, screen sizes, and foldable or resizable configurations. If your test needs system UI, unsupported APIs, WebView behavior, or device-specific fidelity, use a real Android runtime rather than assuming a local simulation is equivalent.
How do I add UI tests?
Views: use Espresso
For a View-based layout, Espresso can locate displayed elements, perform actions, and check results. A useful flow is to launch the screen, perform the same action a user performs, and assert the resulting text, visibility, or navigation destination. Keep assertions focused on observable behavior; implementation details such as a private helper call are not a user contract.
Compose: use Compose testing APIs
Compose tests work through the semantics tree exposed by composables. A typical test creates a rule, renders content or launches an activity, finds a semantic node, performs an action, and asserts the new state.
Rank #4
- PRIVACY DISPLAY: Automatically hide your screen from those beside you. The built-in privacy display can be preset¹ to turn on when receiving notifications, typing passwords, or using specific apps
- TYPE IT IN. TRANSFORM IT FAST: Enhance any shot in seconds on your smartphone by using Photo Assist² with Galaxy AI.³ Add objects, restore details, or apply new styles by simply typing or tapping
- NIGHTS, CAPTURED CLEARLY: From gigs to city lights, record and capture moments after dark with clarity using Nightography so your photos and videos stay crisp and clear on your Samsung Galaxy
- MAKE IT. EDIT IT. SHARE IT: Turn everyday moments into something personal with creative tools built right into your mobile phone, whether it’s a special contact photo, custom wallpaper, an invitation or more⁴
- HELP THAT KEEPS UP: Stay in the moment while Now Nudge with Galaxy AI helps you respond faster and stay organized with smart suggestions⁵ that appear exactly when you need them on your phone
@get:Rule
val composeRule = createComposeRule()
@Test
fun continue_shows_welcome() {
composeRule.setContent {
GreetingScreen()
}
composeRule
.onNodeWithText("Continue")
.performClick()
composeRule
.onNodeWithText("Welcome")
.assertIsDisplayed()
}
The official Compose setup uses androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version"). The ui-test-manifest debug dependency is needed when using createComposeRule(), but not when using createAndroidComposeRule<YourActivity>(). The $compose_version token is a project variable, not a fixed release recommendation; use versions compatible with your project’s current Compose and Android Gradle setup.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteCompose queries can target text, content descriptions, tags, and other semantics. Prefer stable semantics that represent what the user perceives. If a screen mixes Compose and Views, test each part with its appropriate API and add an instrumented flow for the boundary between them.
When should I use Robolectric?
Robolectric runs many Android-oriented tests on the JVM by simulating selected Android classes. It can reduce emulator overhead for legacy code or Android APIs that are difficult to isolate, and it can support some UI behavior checks. Android recommends using it selectively, not wrapping ordinary platform-independent unit tests in Robolectric.
Choose a device or emulator instead when behavior depends on an unsupported or partially supported API, system UI, WebView, exact window behavior, or visual fidelity. A passing simulated test only establishes that the code works in the simulated environment. Keep at least one runtime test for a behavior whose risk lies in the real platform.
How far should an Android test suite go?
Build outward from isolated logic to production-like behavior. Each layer catches a different class of failure.
Recommended Free Tools
| Layer | Typical checks | When to run |
|---|---|---|
| Unit | Use cases, ViewModels, reducers, parsers, validators, and utilities | On every change and locally during development |
| Component or integration | Repository with a database, data mapping, navigation component wiring, or Android resource behavior | Frequently in CI; use the runtime when a JVM test cannot validate the integration |
| Feature | A bounded user capability such as sign-in, search, or checkout state transitions | On pull requests or another frequent CI boundary |
| Application | Navigation across screens, initialization, permissions, and representative end-to-end flows | On a debuggable build in a stable emulator or device matrix |
| Release candidate | Critical flows against a minified, optimized build in an environment close to production | Before release, with the same constraints that can expose release-only failures |
Broad tests are slower and less isolated, so keep their number proportional to the risk and value they cover. A layered suite is more useful than a large collection of overlapping end-to-end scripts. Include navigation and initialization paths that could crash before a user reaches the main screen.
Best Value
- Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Activating is easy, just 3 steps.
- ACTIVATION Promotion: Includes 1500 min, 1500 texts & 1500 MB Data + add more as you need it
- CAMERA SYSTEM: 50MP Quad Pixel camera. Capture sharper, more vibrant photos day or night with 4x the light sensitivity.
- PERFORMANCE: Blazing-fast Qualcomm performance. Get the speed you need for great entertainment with a Snapdragon 680 processor and 4GB of RAM.
- 64GB built-in storage. Get plenty of room for photos, movies, songs, and apps. Made for US
How do I test tablets, resizing, and state restoration?
A phone-sized check can miss clipped content, unusable controls, or incorrect navigation on larger windows. Exercise compact, medium, and expanded window sizes, including resizable windows where your app supports them. UI behavior tests can verify interactions and state; screenshot tests can compare a rendered screen with an approved image to detect visual changes.
Recreate the activity during tests and verify that user-visible UI and navigation state survive the events your app promises to handle:
- Rotation and other configuration changes.
- Window resizing and moving between size classes.
- Process or activity recreation where state restoration is expected.
- Fold and unfold configuration changes on supported foldable profiles.
Posture-specific behavior that reacts to folding without a configuration change needs a device or emulator that supports the relevant posture. A screenshot baseline made on one phone cannot establish correctness for every window size; maintain baselines only for configurations that represent your supported devices.
A practical workflow in Android Studio and CI
- Run local tests first. From Android Studio, run the test class or module test task. Fix deterministic logic failures before starting an emulator.
- Run instrumented tests on a known configuration. Select an emulator or connected device with the API level, orientation, density, and window size the test requires.
- Keep test data deterministic. Seed random data, control the clock, use fake services, and avoid dependence on a developer’s local files or accounts.
- Separate environment failures from product failures. A device-boot timeout, missing system image, or installation error is different from an assertion failure. Record the device profile and test APK output when diagnosing CI.
- Repeat failures at the same scope. Re-run a failing unit test locally, then reproduce an instrumented failure on the same API level and configuration before changing production code.
- Promote valuable tests. If a local simulation repeatedly misses a platform defect, move that behavior to an instrumented test. If an expensive end-to-end test only checks pure transformation logic, split out a local test and retain a smaller integration check.
Common beginner mistakes and fixes
- Putting all logic in activities or fragments: move decisions into ViewModels, use cases, or repositories so most behavior can run locally.
- Calling production services from unit tests: inject a fake or stub and reserve service integration for a controlled integration test.
- Using the wrong UI framework: Compose semantics APIs are for Compose content; Espresso is for View-based UI. Hybrid screens require an intentional boundary.
- Treating Robolectric as a device: add a runtime test for system UI, WebView, unsupported APIs, and fidelity-sensitive behavior.
- Asserting implementation details: check displayed results, navigation, enabled states, and error messages that users can observe.
- Testing only one phone layout: include supported window size classes, resizing, and restoration scenarios.
- Hard-coding a dependency version from a tutorial: align the test libraries with the project’s current Compose, Gradle, Kotlin, and Android plugin versions. Tool labels and compatibility details change over time.
A decision checklist for your next test
- Can this behavior run without Android classes? Write a local JVM test.
- Does it require an Android API that you can safely simulate? Consider Robolectric, then keep a device test if fidelity or support is uncertain.
- Does it exercise a View screen? Use Espresso.
- Does it exercise a Compose screen? Use Compose testing APIs and semantic queries.
- Does it involve lifecycle, resources, system UI, WebView, permissions, a real database, or exact rendering? Prefer an emulator or device.
- Could a change break a tablet, resizable window, foldable posture, rotation, or restored state? Add the corresponding configuration to the test matrix.
- Is the test checking a user outcome rather than a private implementation detail?
Android’s official testing overview was maintained on 2026-03-05 UTC, and the Compose testing page on 2026-10-01 UTC. Android Studio labels, dependency compatibility, and APIs can change, so verify current setup details against the documentation and versions used by your project.
Frequently Asked Questions
Can local tests use an Android context?
A plain local JVM test should not depend on the full Android runtime. If the code genuinely needs Android APIs, either replace that dependency with a fake, use a suitable Robolectric test, or move the check to an instrumented test.
Should every screen have an end-to-end test?
No. Use focused local tests for logic, targeted UI tests for important interactions, and a smaller set of application or release-candidate flows for navigation and initialization risk. The right number depends on the value and cost of each path.
Why did a Compose test pass but the screen still look wrong?
Compose semantics assertions verify exposed nodes and state, not every pixel. Add screenshot coverage for supported window sizes when visual regressions matter, and run fidelity-sensitive checks on an appropriate device or emulator.
Where should a test for a database-backed repository go?
Keep mapping and decision logic in local tests with fakes. Test the actual database integration on an Android runtime when SQL behavior, transactions, resources, or framework integration are part of the risk.
Quick Recap
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.

