Making Mock Objects More Useful
summary
Shows how hand-made Swift mocks become far more useful by changing a boolean flag into a call-count integer, capturing each call’s arguments (or at least the last) and exposing a verify helper that accepts file/line so failures point to the test. Replaces brittle equality checks with predicate closures and integrates Hamcrest-style matchers (e.g., containsInAnyOrder) to ignore irrelevant order and produce rich diffy failure messages. Demonstrates a real refactor bug caught when a method was called twice.
AI-written summary · about
chapters (28)
- 0:00Introduction
- 0:25Why do we need mock objects
- 2:13Cooking
- 2:56Waiter
- 4:46The most common pattern
- 6:05Call count
- 6:43Method parameters
- 7:06Storing arguments
- 7:42Unit tests
- 8:30Extract assertions
- 8:46Errormsgs
- 9:24Parameters
- 10:33Reverse Topics
- 11:07Fragility
- 12:32predicate
- 13:44assert
- 14:33error message
- 14:56error output
- 15:25hand pressed matches
- 15:58matchers
- 17:02helper
- 18:31failure message
- 19:27verify method
- 19:54equal to metric
- 20:13greater than
- 21:05when
- 21:43recommendations
- 22:53our goal








