Testing that the code does what the code does
summary
Argues tests must target observable behavior not implementation details, showing concrete patterns: use red-green-refactor loops, Jest describe blocks for nested behaviors, and double‑loop TDD for acceptance-first drives. Recommends test doubles (H2 as a fake, stubs, spies, mocks) and an adapter layer plus Pact for third‑party contracts. Demonstrates refactors: turn getters/setters into domain types (postcode example), apply Tell‑Don’t‑Ask and Law of Demeter to reduce fragile setup and noisy test failures.
AI-written summary · about
chapters (18)
- 0:00Introduction and context
- 2:11Why we write automated tests
- 5:20Testing behavior not implementation
- 10:38Structuring tests for clarity
- 13:09Red-green-refactor loop explained
- 16:00Defining units of behavior
- 17:44Test doubles and their uses
- 19:31Classical vs London school testing
- 23:02Avoiding backdoor test setup
- 24:45Adapting third-party dependencies
- 26:30Fragile tests signal design issues
- 27:11Leaking state and behavior
- 29:18Primitive obsession and types
- 31:02Test-induced design damage
- 33:31Mocking roles not objects
- 35:18Law of Demeter and tell-don't-ask
- 38:06Effective mocking strategies
- 39:30Key principles and summary








