# Testing Strategy

> Chooses test pyramid layers, what to mock, and where tests live for fn(args, deps) systems. Use this skill when deciding unit vs integration vs e2e coverage or structuring a test approach for a feature. Do not use when/for the red-green-refactor loop itself (use tdd-workflow) or writing individual test cases (use writing-tests).

- Skill: `jagreehal/testing-strategy` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add jagreehal/testing-strategy`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jagreehal/testing-strategy/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: jagreehal (https://skillmd.com/u/jagreehal)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/jagreehal/testing-strategy

---


# Testing Strategy

## Critical rules

- Pyramid: many fast **unit** tests → fewer **integration** → thin **load/chaos** top.
- Unit tests mock deps with `mock<DepsType>()` / `mockDeep` — **never** `vi.mock` for app modules.
- Integration tests use real localhost DB only; guardrails must throw on non-localhost URLs.
- Name by type: `*.test.ts` (unit), `*.test.int.ts` (integration), `load/*.js`, `chaos/*`.
- Hard to test = design smell (`fn-args-deps` mocks only what the function uses).
- Faker for realistic unique fixtures so tests parallelize without cleanup.
- Before long setup/Prisma/Faker examples, read the matching resource below.

## Workflow

1. Pick the layer by the question:
   - Logic / injectable deps? → **Unit** (mock deps, ms)
   - Crosses real boundary (DB, FS)? → **Integration** (`.test.int.ts`, localhost)
   - Concurrent traffic / SLOs? → **Load** (`performance-testing`)
   - Survive dependency failure? → **Chaos** (`performance-testing`)
2. Unit: typed mocks from the deps interface; assert Results and values (`writing-tests`).
3. Integration: real DB, seed unique Faker data, query only that data.
4. Ensure `vitest.setup.ts` enforces localhost DB + `vi.clearAllMocks()` between tests.
5. Prisma fluent API: `mockDeep<PrismaClient>()` (+ `$transaction` callback helper).
6. Load/chaos: critical paths only — see `performance-testing`.

## Resources

- [references/examples.md](references/examples.md) — unit/integration/Prisma/Faker patterns. Read when implementing a layer.
- [references/setup.md](references/setup.md) — file naming, guardrails, vitest config, load smoke sketch. Read when scaffolding the suite.
- [references/rationalizations.md](references/rationalizations.md) — excuse→reality and red flags. Read when tempted to skip the pyramid.

## Validation

- [ ] Each test at the right pyramid layer
- [ ] Unit: `mock<DepsType>()`, no app-module `vi.mock`
- [ ] Integration: `.test.int.ts` + localhost-only guardrail
- [ ] Prisma via `mockDeep`; Faker unique IDs/emails for parallel runs
- [ ] Setup clears mocks between tests

## Constraints

- Not the red-green-refactor loop (`tdd-workflow`) or assertion craft (`writing-tests`).
- Deep k6 profiles and Toxiproxy live in `performance-testing`.
- Adjacent: `fn-args-deps`, `result-types`.

