What problem does it solve?
Test doubles help isolate the code under test (SUT) from dependencies, speeding up unit tests and improving reliability by avoiding flaky external systems.
Core Features & Use Cases
- Stub returns predefined outputs for given inputs and is ideal for state-based tests.
- Mock defines interaction expectations (arguments, call counts, and sequence) and verifies them.
- Spy combines stub behavior with interaction verification.
- Dummy fills argument lists without participating in behavior.
- Fake provides a lightweight in-memory implementation for simple scenarios.
- Use Case: When testing a service that calls a repository, replace the repository with a stub or mock to verify behavior without touching the database.
Quick Start
Identify the DOCs involved, choose appropriate double types, and inject them into your unit tests to isolate the SUT.