TestingVol. 11 · Part XI
0 / 0

Shelves / Testing

TS·121

Testing Projects

Seven build-it-yourself projects that give the tiffin centre a test suite you'd trust to deploy on: a measured test strategy, a unit suite hardened by mutation testing, integration tests against real dependencies, consumer-driven contracts with a deploy gate, a small set of resilient end-to-end journeys, performance tests as regression gates, and a chaos experiment programme, each with milestones, measurable definitions of done and stretch goals.

11 topics · ~7 min read · 5-question quiz
Updated Suggest a correction

How to approach the projects

One system, tested at every level

The labs in this volume tested one level at a time. These projects build a complete, fast, trustworthy test suite around one system: the tiffin centre's services (orders, kitchen, payments, delivery) from earlier volumes, or a service you own. Everything runs on a laptop or CI runner: pytest, JUnit 6, Go's testing or Vitest for units; Testcontainers or a CI service container for PostgreSQL and a broker; Pact with a Pact Broker (the open-source one runs in a container); Playwright; k6; Toxiproxy and, on Kubernetes, Chaos Mesh or LitmusChaos.

# Project Main chapters Roughly
1 A measured test strategy Start Here, 114 a weekend
2 A unit suite that bites 115 1 week
3 Integration tests against real dependencies 116 1 week
4 Contracts with a deploy gate 117 1 week
5 A few journeys you can trust 118 1 week
6 Performance as a regression gate 119 1 week
7 A chaos experiment programme 120 1–2 weeks

New to testing? Do them in order. Experienced? Do project 1 to measure where you stand, then go straight to the stretch goals of the weakest level.

The working method

  1. Measure before and after: suite time per level, flake rate, mutation score, escaped defects, time from commit to deployable.
  2. Write the definition of done as a check that runs in CI, not a wiki page.
  3. Break the code on purpose: every project includes deliberately introducing a bug and watching the right test, at the right level, catch it.
  4. Keep it fast: the gating suite on a pull request should finish in under ten minutes; anything slower moves to a later stage.
  5. Write a README per project with decisions, numbers and what you'd do next.

The seven projects

Project 1: a measured test strategy

Goal. A written, measured picture of what is tested at which level, and a plan to fix the gaps.

Milestones. Count tests by level and time each level (pytest --durations, JUnit reports, Playwright's reporter) → measure the flake rate over 20 CI runs → list the last ten production bugs and the level that should have caught each → write a one-page strategy: what each level owns, what runs on every commit, what runs nightly → wire the levels into separate CI stages.

Done when. A dashboard or report shows test counts, durations and flake rate per level; each of the ten bugs has a test at the level the strategy assigns; the pull-request stage runs in under ten minutes.

Stretch. Test impact analysis: run only tests affected by a change (Bazel, Gradle's predictive selection, or a coverage map), and measure the time saved and anything missed.

Project 2: a unit suite that bites

Goal. Unit tests that are fast, deterministic and demonstrably able to catch bugs.

Milestones. Table-driven tests at every business-rule boundary (fees, coupons, opening hours, tax) → property tests for invariants and round-trips (totals never negative, encode/decode, sorting) → clocks, randomness and IDs injected everywhere → mutation testing (mutmut, PIT, Stryker, cargo-mutants) on the domain modules, with survivors triaged → -race or equivalent concurrency checks in CI.

Done when. The domain modules' mutation score has only documented equivalent mutants surviving; the unit suite runs in under 30 seconds; running it under TZ=Pacific/Auckland and a non-English locale passes; one deliberately introduced off-by-one is caught.

Stretch. Model-based property testing: a Hypothesis state machine (or jqwik's) driving the order lifecycle against a simple reference model.

Project 3: integration tests against real dependencies

Goal. Every adapter (database, broker, HTTP clients, cache) is tested against the real thing, quickly and in isolation.

Milestones. Testcontainers (or CI service containers) for PostgreSQL, the broker and Redis, with the production major versions → migrations applied once per run; rollback per test, per-worker databases for parallel runs → deterministic concurrency tests for every "check then act" (bookings, stock, coupons) → HTTP fakes (WireMock, MSW, respx) covering errors, bad bodies, slowness and resets for each external client → consumer tests that a broker message is processed exactly once despite redelivery.

Done when. No integration test uses SQLite, H2 or a mocked repository; the oversell race from chapter 116 has a test that fails without the fix; every external client has tests for timeout, 5xx and malformed responses; the integration stage runs in under five minutes in parallel.

Stretch. Snapshot a realistic, anonymised production-sized dataset and run the slowest queries' integration tests against it nightly, with an EXPLAIN check that each still uses its index.

Project 4: contracts with a deploy gate

Goal. Services evolve their APIs and events independently without breaking each other.

Milestones. Consumer Pact tests for every HTTP dependency between your services → message pacts for the main events (order.placed, order.ready) → a Pact Broker with pacts published per branch and version → provider verification triggered by pact changes (webhooks) and by provider builds → can-i-deploy gating each deployment, and record-deployment after it.

Done when. Renaming a field a consumer uses fails the provider's build with a clear diff; adding a field passes; a deploy of an incompatible version to the staging environment is blocked by can-i-deploy; one real breaking change has shipped through expand and contract.

Stretch. Bi-directional contracts for a third-party-facing API: verify consumer pacts against the provider's OpenAPI spec, and add oasdiff breaking-change checks for the spec itself.

Project 5: a few journeys you can trust

Goal. A handful of end-to-end journeys that catch real integration failures and almost never flake.

Milestones. Choose at most ten critical journeys (browse menu, place order, pay, track delivery, kitchen marks ready) → Playwright with role and label locators only, web-first assertions, no sleeps → per-test data created through the API, login via saved storage state → network interception for hard-to-produce states (payment failure, slow menu) around the fully real happy paths → traces, videos and screenshots retained on failure → accessibility checks (axe) on each journey's pages.

Done when. The suite runs in under five minutes, sharded if needed; 50 consecutive CI runs have zero flaky failures; a redesign that changes classes and layout but not behaviour leaves all tests green; a deliberately broken API response is caught with a trace that shows it.

Stretch. Run the journeys continuously against production as synthetic monitoring, feeding the SLOs from Volume 9.

Project 6: performance as a regression gate

Goal. Know the system's capacity, and catch performance regressions before they ship.

Milestones. A workload model from real (or realistic) traffic: mix of endpoints, arrival rates, data sizes → k6 scenarios for smoke, load at expected peak, stress past capacity, spike and a 4-hour soak → thresholds on p95, p99 and error rate per endpoint → a dedicated, stable environment for comparisons → a CI job comparing each main-branch build against the previous baseline over repeated runs → capacity figures for each service, checked against Little's law.

Done when. The capacity and breaking behaviour of each service is documented with measurements; a deliberately added 5 ms per request is flagged by the regression job; the soak test shows flat memory and latency over 4 hours; dropped_iterations is zero in every passing run.

Stretch. Run the stress test with load shedding on and off (Volume 9, chapter 105) and show goodput at 150% of capacity with each.

Project 7: a chaos experiment programme

Goal. Regular experiments that turn assumptions about resilience into evidence.

Milestones. Steady-state metrics per service (success rate and latency from Volume 9's SLIs) → an experiment catalogue drawn from incidents and architecture (slow database, broker down, payment provider 5xx, pod loss, zone loss, clock skew) → Toxiproxy in integration environments and Chaos Mesh or LitmusChaos on the cluster → automated abort conditions from monitoring, with rollback → fixes (deadlines, budgets, fallbacks, breakers, shedding) verified by rerunning the same experiment → a quarterly game day with the on-call team.

Done when. At least six experiments run automatically on a schedule in staging with recorded results; each rejected hypothesis led to a fix and a passing rerun; aborts trigger within five seconds of breaching their limit; one game day's findings changed a runbook.

Stretch. Run the safest experiment (one pod killed during business hours) in production with a tight blast radius and automated abort, and write up the outcome.

Tracking your progress

Portfolio checklist

Keep the tests, CI configuration, experiment definitions, measurements and READMEs in Git. Testing evidence is numbers about bugs you caught and time you saved: "PR stage 14 → 7 min; flake rate 3% → 0.1% over 200 runs; domain mutation score 61% → 97% (only equivalents left); oversell race caught by a deterministic test; field rename blocked by can-i-deploy; 8 journeys, 0 flakes in 50 runs; +5 ms regression flagged at p95; slow-DB hypothesis rejected, fixed with deadline + fallback, rerun 100% success" is what makes the portfolio credible.

Mapping to mastery levels

Completing projects 1–3 with their checks puts you at L2 across the volume. Doing their stretch goals and explaining every mechanism is L3–L4. Designing and defending projects 4–7 (contract workflows, E2E strategy, performance engineering and a chaos programme) is L5 work, the level senior and staff interviews about quality and reliability probe.