Test Strategy
Purpose
Allocate testing effort where it catches the most defects per minute of CI time. The
skill maps the test pyramid onto a concrete portfolio per service, sets flaky-test and
quarantine policy, and decides when a layer is being abused (giant E2E suites, mock
pyramids, untested integration seams).
When to Use / When NOT to Use
Use when:
- Planning tests for a new service, feature, or migration ("design the test plan").
- An existing suite is slow, flaky, or misses production defects.
- Deciding whether a behavior belongs in a unit, integration, contract, or E2E test.
Do NOT use when:
- Writing the tests themselves — use
testing/unit-testing for the how.
- Setting coverage thresholds — use
testing/test-coverage.
- Performance/load testing design — use
performance for the method.
Prerequisites & Assumptions
- The service architecture is known (modules, external dependencies, contracts).
- CI can run at least two stages (fast PR gate, deeper post-merge/nightly).
- Contract definitions exist (OpenAPI/proto) for service boundaries.
Step-by-Step Workflow
- Inventory behaviors and risks — list core business invariants, money/data
paths, and integration seams. Risk ranks the portfolio, not habit.
- Assign layers using the decision table below; write the allocation as one
line per behavior.
- Define the CI split — PR gate runs unit + affected integration (<10 min);
post-merge runs full integration + contract; nightly runs E2E and load smoke.
- Set the flaky policy — quarantine, diagnose within 24h, delete or fix within
a week; a quarantined test still tracks an issue.
- Prepare test data rules — synthetic fixtures in code, builders over shared
mutable fixtures, seeded databases per run (containers), never production data.
- Review quarterly — remove tests that duplicate lower layers, promote tests
that caught real bugs, retire tests that never failed and guard nothing.
Layer decision table
| Behavior |
Layer |
Rationale |
| Pure logic, validation, mappers |
Unit |
Fast, exhaustive edge cases |
| Service + real DB/cache/queue (containers) |
Integration |
Real SQL semantics, transactions, migrations |
| Public API request/response shape |
Contract |
Prevents breaking consumers; runs against spec |
| Critical user journeys across services |
E2E (few!) |
Expensive, flaky — keep ≤ 10 journeys |
| Failure modes (downstream down, timeouts) |
Integration with fault injection |
Cannot be reproduced in unit tests honestly |
Enterprise Rules & Standards (MUST / MUST NOT)
- MUST keep the PR gate under 10 minutes; everything slower runs post-merge or
nightly.
- MUST have contract tests for every public service API; a breaking change
fails CI before review (see
api-design versioning).
- MUST quarantine flaky tests with an issue within 24 hours; re-enabling without
a fix is forbidden.
- MUST keep E2E suites ≤ 10 critical journeys; anything more belongs lower in
the pyramid.
- SHOULD target roughly 70% unit / 20% integration / 10% E2E of test count and
90/9/1 of execution time.
- SHOULD test failure modes explicitly (dependency timeout, 500, malformed
input) at the integration layer with fault injection.
- MUST NOT use the production database or production data in any test.
- MUST NOT allow a test to depend on execution order or shared mutable state.
Examples
Good — CI split (GitHub Actions sketch):
jobs:
unit: # PR gate, ~2 min
script: go test -race -count=1 ./...
integration: # post-merge, containers for pg/redis
script: docker compose up -d && go test -tags=integration ./test/integration/...
e2e: # nightly, staging deploy
script: make deploy-staging && run-journeys
Bad — the inverted pyramid:
One giant E2E suite (400 tests, 45 min) decides everything; unit tests exist
for trivial helpers only.
Why it fails: feedback is slow, failures are ambiguous ("which of 14 services
broke?"), and core logic is verified only through the whole system.
Checklist
Common Pitfalls
- E2E accumulation — every new bug becomes "add an E2E test"; push coverage down
the pyramid instead.
- Mock pyramid — thousands of unit tests asserting on mocks while seams rot;
contract + integration tests own the seams.
- Shared staging as test env — cross-team interference; use ephemeral
environments per run.
- Flake normalization — "just rerun it" culture; reruns hide real intermittent
defects (races, clock issues).
References
1---2name: test-strategy3description: 'Decides what to test at which layer — unit vs integration vs contract vs end-to-end — and designs the test portfolio for a service or repository. Trigger with "what tests do we need", "our E2E suite is too slow", or "design the test plan for this feature".'4metadata:5 source: https://skillmd.com/skills/pnguyen215/test-strategy6---78# Test Strategy910## Purpose1112Allocate testing effort where it catches the most defects per minute of CI time. The13skill maps the test pyramid onto a concrete portfolio per service, sets flaky-test and14quarantine policy, and decides when a layer is being abused (giant E2E suites, mock15pyramids, untested integration seams).1617## When to Use / When NOT to Use1819Use when:2021- Planning tests for a new service, feature, or migration ("design the test plan").22- An existing suite is slow, flaky, or misses production defects.23- Deciding whether a behavior belongs in a unit, integration, contract, or E2E test.2425Do NOT use when:2627- Writing the tests themselves — use `testing/unit-testing` for the how.28- Setting coverage thresholds — use `testing/test-coverage`.29- Performance/load testing design — use `performance` for the method.3031## Prerequisites & Assumptions3233- The service architecture is known (modules, external dependencies, contracts).34- CI can run at least two stages (fast PR gate, deeper post-merge/nightly).35- Contract definitions exist (OpenAPI/proto) for service boundaries.3637## Step-by-Step Workflow38391. **Inventory behaviors and risks** — list core business invariants, money/data40 paths, and integration seams. Risk ranks the portfolio, not habit.412. **Assign layers** using the decision table below; write the allocation as one42 line per behavior.433. **Define the CI split** — PR gate runs unit + affected integration (<10 min);44 post-merge runs full integration + contract; nightly runs E2E and load smoke.454. **Set the flaky policy** — quarantine, diagnose within 24h, delete or fix within46 a week; a quarantined test still tracks an issue.475. **Prepare test data rules** — synthetic fixtures in code, builders over shared48 mutable fixtures, seeded databases per run (containers), never production data.496. **Review quarterly** — remove tests that duplicate lower layers, promote tests50 that caught real bugs, retire tests that never failed and guard nothing.5152### Layer decision table5354| Behavior | Layer | Rationale |55| ------------------------------------------ | -------------------------------- | ---------------------------------------------- |56| Pure logic, validation, mappers | Unit | Fast, exhaustive edge cases |57| Service + real DB/cache/queue (containers) | Integration | Real SQL semantics, transactions, migrations |58| Public API request/response shape | Contract | Prevents breaking consumers; runs against spec |59| Critical user journeys across services | E2E (few!) | Expensive, flaky — keep ≤ 10 journeys |60| Failure modes (downstream down, timeouts) | Integration with fault injection | Cannot be reproduced in unit tests honestly |6162## Enterprise Rules & Standards (MUST / MUST NOT)6364- **MUST** keep the PR gate under 10 minutes; everything slower runs post-merge or65 nightly.66- **MUST** have contract tests for every public service API; a breaking change67 fails CI before review (see `api-design` versioning).68- **MUST** quarantine flaky tests with an issue within 24 hours; re-enabling without69 a fix is forbidden.70- **MUST** keep E2E suites ≤ 10 critical journeys; anything more belongs lower in71 the pyramid.72- **SHOULD** target roughly 70% unit / 20% integration / 10% E2E of test count and73 90/9/1 of execution time.74- **SHOULD** test failure modes explicitly (dependency timeout, 500, malformed75 input) at the integration layer with fault injection.76- **MUST NOT** use the production database or production data in any test.77- **MUST NOT** allow a test to depend on execution order or shared mutable state.7879## Examples8081Good — CI split (GitHub Actions sketch):8283```yaml84jobs:85 unit: # PR gate, ~2 min86 script: go test -race -count=1 ./...87 integration: # post-merge, containers for pg/redis88 script: docker compose up -d && go test -tags=integration ./test/integration/...89 e2e: # nightly, staging deploy90 script: make deploy-staging && run-journeys91```9293Bad — the inverted pyramid:9495```text96One giant E2E suite (400 tests, 45 min) decides everything; unit tests exist97for trivial helpers only.98```99100Why it fails: feedback is slow, failures are ambiguous ("which of 14 services101broke?"), and core logic is verified only through the whole system.102103## Checklist104105- [ ] Every behavior assigned to a layer with a one-line rationale.106- [ ] PR gate < 10 min; full suite split across post-merge/nightly stages.107- [ ] Contract tests cover all public service APIs.108- [ ] Flaky-test quarantine process exists and is enforced.109- [ ] Test data is synthetic, per-run, and never production-derived.110- [ ] Quarterly portfolio review scheduled (owner named).111112## Common Pitfalls113114- **E2E accumulation** — every new bug becomes "add an E2E test"; push coverage down115 the pyramid instead.116- **Mock pyramid** — thousands of unit tests asserting on mocks while seams rot;117 contract + integration tests own the seams.118- **Shared staging as test env** — cross-team interference; use ephemeral119 environments per run.120- **Flake normalization** — "just rerun it" culture; reruns hide real intermittent121 defects (races, clock issues).122123## References124125- Practical Test Pyramid (Hambrick): https://martinfowler.com/articles/practical-test-pyramid.html126- Google SRE — flaky tests chapter: https://sre.google/sre-book/addressing-cascading-failures/ (see also flaky test chapters)127- Pact contract testing: https://docs.pact.io/