Learning to avoid fakes
A fake is any test double that has any kind of logic or control structure within it, such as conditional statements or loops. Other types of test object, such as spies and stubs, are made up entirely of variable assignments and function calls.
One type of fake you'll see is the in-memory repository. You can use these in place of SQL data stores, message brokers, and other complex sources of data.
Fakes are useful when testing complex collaborations between two units. We'll often start by using spies and stubs and then refactor to a fake once the code starts to feel unwieldy. A single fake can cover a whole set of tests, which is simpler than maintaining a whole bunch of spies and stubs.
We avoid fakes for these reasons: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access