Test Double
ELI5 — The Vibe Check
Test double is the umbrella term for anything that replaces a real dependency in a test. Mocks, stubs, spies, fakes — they're all test doubles. Like how 'stunt double' covers all the different types of stunt performers. Mock is just the most famous type.
Real Talk
A test double is any object that stands in for a real dependency during testing. The term (coined by Gerard Meszaros) encompasses stubs (fixed responses), mocks (verifiable behavior), spies (call recording), fakes (simplified implementations), and dummies (placeholder objects).
When You'll Hear This
"Replace that external dependency with a test double." / "Whether you call it a mock or stub, it's all a test double."
Related Terms
Dependency Injection
Instead of your UserService creating its own DatabaseConnection (tight coupling), you pass the database in from outside: new UserService(db).
Mock
A mock is a fake version of something your code talks to.
Spy
A spy is like a double agent — it lets the real function still do its job, but secretly records everything: how many times it was called, with what argumen...
Stub
A stub is like a cardboard cutout of a function. It stands in for the real thing and always gives you the same canned response.
Unit Test
A unit test is like checking that one single LEGO brick isn't broken before you use it in your big castle.