1---2name: testing-strategy3description: Use when designing test architecture, building API test suites, validating API contracts, setting up component or E2E testing, managing test data, debugging flaky tests, reviewing coverage strategy, or organizing test files. Covers test pyramid, mocking (MSW), frontend (React Testing Library, Playwright), and CI integration.4---5
6# Testing Strategy
7
8Comprehensive testing guidance for test architecture, coverage strategy, and test design.
9
10## Test Pyramid
11
12| Level | Speed | Cost | Confidence | Share |
13|-------|-------|------|------------|-------|
14| **Unit** | ~1ms | Low | Narrow | 65-80% |
15| **Integration** | ~100ms | Medium | Medium | 15-25% |
16| **Contract** | ~10ms | Low | API shape | Part of unit |
17| **E2E** | ~1s+ | High | Broad | 5-10% |
18
19## Key Principles
20
21- Test behavior, not implementation — test what code does, not how
22- For behavior changes, write the failing test first and verify it fails for the expected reason
23- Follow the testing pyramid — more unit tests, fewer E2E
24- Use meaningful coverage metrics — branch coverage over line coverage
25- Prevent flaky tests — no arbitrary waits, no test interdependence
26
27## When NOT to Use
28
29- For TDD discipline during implementation — see work-session anti-rationalization reference
30- For security testing — see security-audit skill
31
32## Quick Start Checklist
33
341. Choose test framework (Vitest recommended for new projects)
352. Design test folder structure mirroring source
363. Write unit tests for pure logic and utilities
374. Add integration tests for API endpoints and data flows
385. Add contract tests against OpenAPI spec (if applicable)
396. Add E2E tests for critical user journeys only
407. Set up CI to run tests on every PR
418. Before completion claims, run `verification-before-completion` and cite the fresh command result
42
43## What NOT to Test
44
45- Framework internals (React rendering, Express routing)
46- Third-party library behavior
47- Trivial getters/setters with no logic
48- Implementation details (private methods, internal state)
49
50## References
51
52| Reference | Description |
53|-----------|-------------|
54| [test-architecture-structure.md](references/test-architecture-structure.md) | Project structures, shared utilities, test configuration |
55| [test-architecture-isolation.md](references/test-architecture-isolation.md) | Playwright config, database isolation, performance optimization |
56| [test-design-techniques.md](references/test-design-techniques.md) | Equivalence partitioning, boundary values, decision tables, state transitions |
57| [test-design-error-and-advanced.md](references/test-design-error-and-advanced.md) | Error handling tests, property-based testing, parameterization, regression |
58| [frontend-react-testing.md](references/frontend-react-testing.md) | React Testing Library, queries, user events, hooks, forms |
59| [frontend-vue-a11y-visual.md](references/frontend-vue-a11y-visual.md) | Vue Test Utils, accessibility, visual/Storybook testing, anti-patterns |
60| [e2e-playwright.md](references/e2e-playwright.md) | Playwright POM, fixtures, auth state, API mocking, visual comparison |
61| [e2e-cypress-and-stability.md](references/e2e-cypress-and-stability.md) | Cypress patterns, flaky test prevention, test data, debugging |
62| [mocking-fundamentals.md](references/mocking-fundamentals.md) | Mock decision tree, stubs/mocks/spies/fakes, MSW setup and usage |
63| [mocking-modules-and-patterns.md](references/mocking-modules-and-patterns.md) | Module mocking, time mocking, anti-patterns, dependency injection |
64| [coverage-guide.md](references/coverage-guide.md) | Coverage metrics, meaningful thresholds, CI integration |
65| [api-test-frameworks-setup.md](references/api-test-frameworks-setup.md) | Vitest and Jest setup, configuration, running tests |
66| [api-test-supertest-and-helpers.md](references/api-test-supertest-and-helpers.md) | Supertest usage, request helpers, custom matchers, snapshots, debugging |
67| [api-integration-patterns.md](references/api-integration-patterns.md) | CRUD endpoint tests, relationship tests |
68| [api-auth-patterns.md](references/api-auth-patterns.md) | Login/logout, protected routes, authorization, auth helpers |
69| [api-e2e-and-edge-cases.md](references/api-e2e-and-edge-cases.md) | Multi-step workflow tests, error responses, edge cases |
70| [api-test-data-factories.md](references/api-test-data-factories.md) | Factory patterns, builders, fixtures |
71| [api-test-data-database.md](references/api-test-data-database.md) | Database helpers, cleanup strategies, data generation |
72| [api-contract-openapi.md](references/api-contract-openapi.md) | OpenAPI/AJV schema validation, contract tests |
73| [api-contract-zod-advanced.md](references/api-contract-zod-advanced.md) | Zod validation, response shape testing, breaking change detection |
74| [api-test-ci-pipelines.md](references/api-test-ci-pipelines.md) | CI pipeline strategy, GitHub Actions, parallel execution |
75| [api-test-ci-environments.md](references/api-test-ci-environments.md) | Environment config, test reporting, database services, E2E environments |
76| [anti-rationalization.md](references/anti-rationalization.md) | Iron Law, common rationalizations, red flag STOP list for TDD discipline |
77
78## Runtime Notes
79
80- **Claude Code**: dispatch yokay-test-runner via the Task tool with `subagent_type: "pokayokay:yokay-test-runner"`.
81- **Codex**: there is no subagent dispatch. Execute the agent's role inline — read the corresponding `agents/yokay-<name>.md` and follow its Behavioral Defaults, Critical Rules, and Output Contract directly in the current session.