Substituting dependencies.
WHAT THE TYPES ARE
Dummies, passed but unused Stubs, returning fixed values Spies, recording calls Mocks, with expectations about calls Fakes, working implementations that are simpler
WHAT STUBS SUIT
Supplying data the test needs.
WHAT MOCKS SUIT
Verifying an interaction occurred.
WHAT FAKES SUIT
Replacing something heavy with something light: an in-memory store rather than a database.
WHAT OVER-MOCKING PRODUCES
Tests verifying that the code calls what you wrote it to call.
WHY THAT IS WORTHLESS
It restates the implementation, and passes even when behaviour is wrong.
WHAT TO PREFER
Real objects where they are cheap Fakes where they are not Mocks only at genuine boundaries
WHAT COUNTS AS A BOUNDARY
External services, time, randomness, the file system, the network.
WHY TIME AND RANDOMNESS SPECIFICALLY
They make tests fail intermittently.
WHAT TO DO ABOUT THEM
Supply them as dependencies, controlled in tests.
WHAT TO BE CAREFUL WITH
Doubles diverging from the real thing.
WHAT THAT CAUSES
Tests passing while the integration is broken.
WHAT GUARDS AGAINST IT
Contract tests against the real implementation.