testing-setup

Installation
SKILL.md

Step 1: Analyze the current testing setup

To understand the testing setup of an existing project, look for these key dependencies in the project's configuration (e.g., libs.versions.toml or build.gradle):

  1. Dependency Injection: Identify the framework (e.g., Hilt, Koin, vanilla Dagger).
  2. Unit Testing: Identify the core framework (JUnit 4 or JUnit 5).
  3. Mocking/Fakes: Identify the preferred approach (see Manual Fakes First in Step 2).
  4. Coroutine & Flow Testing: Check for utilities like kotlinx-coroutines-test and Turbine.
  5. Screenshot Testing: Check whether Roborazzi is declared (only expected in a :design-system module).
  6. Environment: Ensure the JDK and AGP versions are compatible with the project's compileSdk and testing tools (see dependency-manager).

Step 2: Set up the Testing Infrastructure

Configure the chosen frameworks following their official guidelines. Ensure that:

  • Testing dependencies are correctly scoped (testImplementation for pure JVM tests). Do NOT declare androidTestImplementation dependencies (Espresso, ui-test-junit4, UI Automator) unless a module explicitly needs them under Step 5 (Design System exception).
  • A clear boundary exists between production and test code.
  • MainDispatcherRule: Every module that tests ViewModels (or any code using viewModelScope / stateIn) MUST provide a single reusable JUnit rule that calls Dispatchers.setMain(UnconfinedTestDispatcher()) in starting() and Dispatchers.resetMain() in finished(). Without it, pure JVM tests fail with Module with the Main dispatcher had failed to initialize.
  • Manual Fakes First: When a domain interface exists (repository, data source, API service), write a hand-made Fake* implementation (in-memory, deterministic) instead of using a mocking framework (MockK / Mockito). Fakes are faster, have no bytecode-instrumentation cost, and do not couple tests to implementation details (coVerify-style assertions). Mocking frameworks are only acceptable for types that cannot be faked (final platform classes) and only when explicitly justified.
Installs
23
First Seen
Aug 10, 2026