Frequent questions about test doubles: how many exist, why the family matters, and whether they replace integration tests.
- How many test doubles?
Five flavors (dummy, stub, spy, mock, fake). Some frameworks blur the lines; the taxonomy is a mental model, not a class hierarchy.
- Do they replace integration tests?
No. Doubles prove the unit is correct in isolation; integration tests prove the system works when the real dependencies are in play.
- Are test doubles cheating?
Only if they lie. A well-designed double (a fake that behaves like the real thing, a stub that returns plausible input) makes tests more honest, not less.
- Should I always use the same framework?
The taxonomy is language-agnostic. Sinon, Jest, Mockito, PHPUnit, RSpec all implement the same five ideas under different names.