Test double
Also called: Fake, Stub, Mock, Spy
A stand-in for a real dependency in a test, such as a fake payment gateway, so the test is fast, repeatable and safe.
Definition
Test doubles replace dependencies that are slow, random or external. A fake has a simple working implementation (an in-memory store), a stub returns prepared answers, a spy records how it was called, and a mock verifies expected calls. They are passed in through the constructor, which is why code designed with dependency injection is easy to test.
In practice
A FakeGateway that can be told to fail lets a test check the "payment failed" screen without a real card.
Learn it in context
Lessons that use this term.