Mocking your codebase without cursing it
summary
Argues that mocks should only cover coordination, not business logic, and that constraining design yields smaller, testable pieces; uses Go examples, hand‑rolled function mocks and testify/mock (tip: use testify mock and call its Test method), recommends generators or LLMs for boilerplate, and shows a RAG-style incident‑report coordinator as a concrete example. Advises to limit collaborators to three or four and write two tests per collaborator (happy + error), mock only direct collaborators, avoid mixing real objects with mocks, and layer with integration and end‑to‑end tests.
AI-written summary · about
chapters (15)
- 0:00Introduction to mocking
- 1:02What mocks are
- 2:04Mock examples in Go
- 4:53History and design benefits
- 6:16Real-world example
- 7:39Outside-in testing
- 8:21Coordinators vs logic
- 9:25How mocks go wrong
- 10:27Business vs sociable tests
- 13:18Common mocking smells
- 16:32Concerns about mocks
- 18:40Mocks limitations
- 20:23Test pyramid explained
- 23:35Key takeaways
- 25:20Practical advice
