home/coding/tests

Tests

GPTClaudeDeepSeek··1,253 copies·updated 2026-07-14
tests.prompt
# Tests (Unit / Integration / UI / Performance)

This prompt defines test scope, frameworks, and style for projects using MVVM, Repository, and ViewModel. Goal: prioritize unit tests in layers that do not depend on the Android framework; add integration and UI tests when needed. Scope, rules, and required operations are stated only in this file.

---

## Scope

- Test requirements when adding or changing ViewModel, Repository, UseCase, utilities, or network/DB boundaries. Prioritize unit tests for ViewModel, Repository, UseCase; prefer Fakes over heavy mocks.

---

## Unit tests

### Framework and dependencies

- **JUnit** — JUnit 4 or 5 (match project); use assertThat or JUnit 5 assert*.
- **Mockito / MockK** — Per project; Kotlin projects often prefer **MockK** for coroutines and final classes.
- **Coroutines** — If code uses suspend/Flow, use **CoroutineTestRule** or **runTest** (kotlinx-coroutines-test) so tests control Dispatcher and timing.

### Structure and naming

- **Structure** — Given/When/Then or AAA (Arrange, Act, Assert); one behavior per test.
- **Naming** — Describe “under what condition, what happens, what is expected”, e.g. whenUserNotFound_shouldEmitErrorState or loadProfile_success_returnsData.

### Subject and doubles

- **ViewModel** — Inject Fake Repository or MockK; collect StateFlow/LiveData and assert state and side effects (e.g. navigation).
- **Repository** — Inject Fake DAO / Fake API or MockK; assert call count/args and Flow/suspend result.
- **UseCase** — Inject Fake Repository; assert input→output and error paths.
- **Utilities** — Pure functions: test directly; if they use Context/system API use mocks or Android test deps (e.g. robolectric) as needed.
- **Doubles** — Prefer **Fake** (lightweight real behavior) over complex **Mock** for readability and stability.

### Scenarios

- **Success** — Normal input and dependency return.
- **Failure** — Network error, empty data, exception, permission; assert error state or exception type.
- **Boundaries** — Empty list, empty string, edge values.

### Example request (for AI)

when to use it

Community prompt sourced from the open-source GitHub repo afkT/DevAICode-Android (Apache-2.0). A "Tests" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.

tags

codingcommunitydeveloper

source

afkT/DevAICode-Android · Apache-2.0