---
description: Test-driven development standards for production code — RED-GREEN-REFACTOR, coverage targets, mocking strategy. Loads conditionally via paths on test files and src/ code.
paths:
  - "**/*.test.*"
  - "**/*.spec.*"
  - "**/__tests__/**"
  - "**/tests/**"
  - "**/test/**"
  - "src/**/*.ts"
  - "src/**/*.tsx"
  - "src/**/*.js"
  - "src/**/*.jsx"
  - "src/**/*.py"
---

# Testing Standards

Test-driven development is mandatory for production code. Code without tests is incomplete. TDD cycle: RED → GREEN → REFACTOR. See `build-tdd` skill for the full process.

## Coverage Requirements

- Minimum: 80% line coverage across the project
- Critical paths: 100% coverage required (auth, payments, security, data mutations)
- Coverage is necessary but not sufficient — test quality matters more than numbers

## Test Types Required

| Type | Covers | Required |
|------|--------|----------|
| Unit | Individual functions, edge cases | Always |
| Integration | Component interactions, API contracts | Always |
| E2E | Full user flows via browser/client | For user-facing features |

## Test Quality

- Every test must fail first (proves it tests something real)
- One behavior per test — not multiple assertions testing different things
- Test edge cases: null/undefined, empty collections, boundary values, error paths
- Use descriptive test names that explain the behavior being verified

## Mocking Strategy

| Test Level | External Services | Internal Dependencies |
|---|---|---|
| **Unit** | Mocks OK — isolate the unit | Mocks OK |
| **Integration** | SHOULD use real if available, mocks require documented justification | Real |
| **E2E** | MUST use real if confirmed available, BLOCKED if not | Real |

Mock-only suites fail the quality gate. Every external dependency needs at least one integration/E2E test against the real service. E2E tests MUST NOT fall back to fake data on timeout — they FAIL.

**Exemption:** `/hotfix` uses smoke tests + regression test only (not the full test plan). Full test coverage is deferred to the follow-up ticket. See `quality-gates.md` Hotfix Gate Exemptions and `quality-test-execution` Step 2 note.

## Anti-Patterns

- No tests that only verify the mock
- No skipped tests in CI (fix or delete them)
- No test code in production builds
- No flaky tests — fix the root cause or quarantine immediately
