Home / Market / testing setup

testing setup

Analyze and create a testing strategy for Android apps - install testing libraries, set up test infrastructure, create harnesses for unit tests, UI tests, screenshot tests, and end-to-end tests.

skill★ 108443753 dlskills.shApache-2.0Install in CosmosUpstream Source

Documentation & Preview

--- name: testing-setup description: Analyze and create a testing strategy for Android apps - install testing libraries, set up test infrastructure, create harnesses for unit tests, UI tests, screenshot tests, and end-to-end tests. license: Complete terms in LICENSE.txt metadata: author: Google LLC last-updated: '2026-09-30' keywords:

---

Step 1: analyze the current testing setup

To understand the testing setup of an existing project, look for these dependencies in the libs.versions.toml file, or build files:

  1. Dependency Injection framework used. For example, Hilt, Koin, Anvil, or vanilla Dagger.
  2. Unit (local) testing framework this project uses. For example, JUnit4 or JUnit5.
  3. Mocking framework (if any) used for unit tests, and for instrumented and UI tests. For example, Mockito or Mockk.
  4. Robolectric. Identify which of these three uses apply:
  5. Used in unit tests to have fakes for platform entities
  6. To run behavior UI tests without a device or emulator. For example, used to run Espresso or Compose tests.
  7. To do screenshot testing with Roborazzi
  8. Is the app 100% Compose, Views or hybrid?
  9. Behavior UI tests:
  10. Compose Tests (androidx.compose.ui:ui-test-*)
  11. Espresso Tests for Views. Check for wrappers such as Kaspresso. Dependencies: androidx.test.espresso:espresso-core, androidx.test:runner, androidx.test:rules.
  12. Screenshot tests. Identify which of these types the project uses:
  13. Instrumented (device-based). For example, using Dropshots.
  14. Based on Robolectric, so they run locally. For example, using Roborazzi.
  15. Based on LayoutLib, so they run locally. For example, Paparazzi, or the Compose Preview Screenshot Testing tool.
  16. End to end tests (also known as Release Candidate tests) always run on device and use high-level frameworks such as UIAutomator, Appium, or Robotium.
  17. Generate a Markdown report with the analysis

Step 2: Set up Dependency Injection frameworks for testing

If there is no Dependency Injection framework, install one: if it's a multiplatform application, ask the user whether they want to install Koin, or kotlin-inject. If it's not multiplatform, install Hilt.

Install the testing dependencies (for example com.google.dagger:hilt-compiler that should be applied with a kspAndroidTest configuration).

> [!IMPORTANT] > Important: Always consult the documentation of the applicable framework to learn about testing (for example: Hilt testing guide, Koin Instrumented tests).

For instrumented tests, create and configure (by adding testInstrumentationRunner to the build gradle files) a new test runner and apply the testing rules required by the framework (for example in Hilt, annotate your test classes with @HiltAndroidTest and apply the HiltAndroidRule). Other frameworks use other mechanisms, consult their documentation.

Step 3: Install frameworks

Unless otherwise specified, respect the current stack of testing frameworks.

If there are no testing frameworks, and the user didn't specify any preference, install the following:

project's AGP version first, then pick the matching setup and follow it strictly:

Don't combine both setups in the same module. If the project already uses the standalone plugin and its AGP version supports test suites, offer to migrate it using the tasks and paths mapping table in Screenshot testing with test suites.

not install it unless it is clearly necessary.

If instrumented screenshot tests are requested, install Dropshots.

If end-to-end testing is requested, install UI Automator.

Step 4: Refactor and create fakes for testing

Refactor for unit tests

In the next sections you'll be asked to create tests. If you have dependencies on Android framework classes, or entities that are not part of the codebase:

and a "Default" implementation with the existing code. Add the Fake version to the test sourceset (test or androidTest).

interface), mock the dependencies.

Refactor for UI tests

If you need to fake components to make testing easier and faster and more reliable, replace slow and problematic dependencies with fakes. Use runtime fakes using the Dependency Injection framework installed to:

Step 5: Unit testing

Create a task to add or review unit tests in every file that contains business logic (ViewModels, Repositories, and database-related classes such as DAOs). Don't create unit tests for Activities, Compose layouts, or dependency injection configuration files.

Step 6: UI testing

Espresso or Compose UI tests live in the test sourceset because they will be run with Robolectric. If instrumented (emulator or device) tests are requested, put them in the androidTest sourceset.

Step 7: Test databases

If the database is using SQLite (through a library such as Room or SQLDelight), create instrumented tests using an in-memory database to make sure that they work with the SQLite engine on device.

Step 8: Screenshot tests

Regardless of the framework used, screenshot tests focus on two types of tests:

Behavior isn't tested with screenshots, but do test different common scenarios if their UIs change a lot depending on the state. For example, test loading screens by injecting a loading state to the UI or simulating it with a fake.

Step 9: UI Behavior tests

Test the UI logic using behavior tests, which ensures that the UIs react as expected when different states are passed, and when user actions are performed.

Compose UI behavior tests

Views (XML) UI behavior tests

Use Espresso to match views and interact with them.

Step 10: Navigation tests

Create a test suite to verify navigation logic. Include:

Step 11: Simulate different window sizes and settings

For Compose layouts, use DeviceConfigurationOverride described in "UI testing common patterns" to simulate different window sizes, font scales

Step 12: End-to-end tests

Create a low number (about 5% of all tests) of end-to-end tests that cover big user journeys. Use Compose Test APIs or Espresso for that. If you have to access platform features such as notifications or system UI, use UI Automator.

If you need to take screenshots of the app running in a device, use Dropshots. You need a device for screenshot tests when verifying interaction with the system UI (examples: edge-to-edge rendering, notifications, picture-in-picture)

Step 13: Instrumented Screenshot tests

Install the com.dropbox.dropshots plugin in the module and a Dropshots() JUnit Rule. Create a new instrumented screenshot test for one of the app's features.

Step 14: Install jacoco

Install jacoco for local testing code coverage.

Final touches

to the testing strategy. If the user agrees:

changes you've made to the testing strategy.

a description of the testing strategy, including the commands needed to run every type of test and where the screenshot reference files live. Also create a new AGENTS.md file in the root and create a link to docs/testing.md.