$ run as a normal user# run as root (or with sudo)
Skills in this chapter
- Testing — P1022–P1031
A test pyramid that matches the risk
Risk picks the layer.
The test pyramid is usually drawn as a ratio. A better use is as a budget: each layer exists because a different failure is cheapest to catch there.
- Critical Path: Critical journeys, Smoke after deploy, Revenue flow
- Service Boundary: Consumer pact, Schema check, Provider verify
- Unit Logic: Pure functions, Edge cases, Fast suite
Full note: P1022 — A test pyramid that matches the risk
Contract testing between services
Contract testing answers a narrow question: whether the provider still sends what this consumer needs. It does not test the business logic on either side, and it does not replace an end-to-end journey. That narrowness is the point.
- One consumer, one promise: The fields, paths and status codes that consumer actually reads.
- A pact, not a schema: A small JSON record of the request and the response it needs.
- Verify the provider: Replay every pact against a real build, with the state set up.
- Gate the deploy: Publish the result and ask can-i-deploy before the release.
Full note: P1023 — Contract testing between services
Five test smells that hide bugs
Five smells show up in suites that are green and still hide bugs.
- A mock assertion proves the wiring, not the behaviour.
- A fixed sleep hides the race it was meant to fix, and slows the suite.
- A shared fixture that mutates makes test order a hidden dependency.
- Twenty assertions in one test tell you it broke, not what broke.
Full note: P1024 — Five test smells that hide bugs
Tests in CI: lint, unit, contract, e2e, gate
A pipeline is a gate, not a suggestion.
Most CI pipelines run tests. Fewer run them in an order that fails fast and tells you why.
- Lint and types: Style, types and secrets fail before a single test runs.
- Unit: Isolated, parallel, under a minute on a warm cache.
- Contract: Consumer expectations against a real provider build.
- E2E: A few critical journeys on a seeded environment.
Full note: P1025 — Tests in CI: lint, unit, contract, e2e, gate
Test data you can trust
Test data is the part of the suite nobody owns until it breaks. A test fails because a row changed, a date moved or another job deleted a fixture.
- Build, do not copy: Factories that make the smallest valid row, with explicit overrides.
- Isolate the state: A transaction or a schema per worker, from the production migrations.
- Freeze the inputs: Clock, seed and ids controlled so a failure reproduces.
- Protect the data: Synthetic by default; masked copies have an owner and a date.
Full note: P1026 — Test data you can trust
Four numbers worth tracking
Four numbers say more than a coverage badge.
- Coverage shows what ran, not what was checked. Watch the trend, not a target.
- Flake rate counts tests that fail, then pass on a rerun with no code change.
- Runtime: keep the fast suite local and the full suite inside the merge window.
- Escaped defects: bugs found after release. The only number tied to outcomes.
Full note: P1027 — Four numbers worth tracking
Quarantine a flaky test, keep coverage
A skip is a loan, not a fix.
A flaky test is one that fails and passes on the same commit. The worst response is to delete it, because the coverage goes with it and the bug it was hinting at stays.
- Prove it is flaky, not broken: Read the rerun log; Name the failure mode; Open one ticket.
- Skip it in the open: Skip it by name; Pin it to an owner; Keep a shadow run.
- Fix the cause, then unskip: Reproduce with a seed; Fix the cause, not the wait; Unskip on green.
Load testing a design, not a number
A load test that reports ten thousand requests per second has told you a number, not whether the design survives your traffic.
- Ask a question: An SLO, a pass condition and a stop condition before the script.
- Model the mix: Endpoints, ratio, payloads and arrival shape from real traffic.
- Read the tail: p50, p95, p99 and the error rate; find the knee, not the peak.
- Keep it repeatable: Versioned script, pinned tool, raw output and run notes.
Full note: P1029 — Load testing a design, not a number
Five accessibility checks before release
Accessibility checks are cheaper before release than after a complaint, and five of them need no specialist tool.
- Keyboard: every control reachable, in order, with focus always visible.
- Names: every input has a label and every icon button a name.
- Contrast: 4.5:1 for body text, 3:1 for large text and controls.
- Zoom: 200 per cent with no clipped or overlapping text.
Security tests every pipeline should run
A scan is a starting point.
Every pipeline should run a small set of security tests. The list is short because a check nobody triages is worse than no check at all.
- Code:
semgrep ci --config p/default - Deps:
npm audit --audit-level=high - Build:
syft $IMAGE -o spdx-json > sbom.json - Runtime:
nuclei -u $STAGING_URL