Mocking, Stubbing & Test Doubles
What test doubles actually are, the difference between a dummy, stub, fake, spy, and mock, and the judgment call of when to fake a dependency versus use the real thing.
Download EPUB- Why Fake Anything? Your code talks to slow, unreliable, and expensive things; to test your own logic in isolation you replace those dependencies with stand-ins - the stunt-double mental model.
- The Doubles, Clearly Defined The five kinds of test double - dummy, stub, fake, spy, and mock - what each is for, with a small example, and why people call all of them 'mocks.'
- When Mocking Helps vs Hurts Mock at the boundaries (external systems), not your own internals; avoid the over-mocking trap of green tests over a broken product; prefer real objects or fakes when they're cheap.