Skip to content

Why it matters

Test doubles make unit tests possible: without them, every test would need a database, a network and a clock, which would make the suite slow and flaky.

A unit test is meant to test one thing: one function, one method, one unit. If that unit calls a database, a payment gateway or time.now(), testing it in isolation requires replacing those dependencies. Test doubles are the way. Without them, "unit test" would be a euphemism for "integration test that takes 50 ms and fails on Tuesdays".