Test doubles 是在测试中代替真实依赖项的对象 — 包括 mocks、stubs、spies、fakes 和 dummies。它们将被测代码与其依赖项(数据库、API、服务)隔离开来,使得能够进行快速、专注、受控的单元测试。
Test doubles 的原因
To test a unit in ISOLATION, replace its real dependencies (DB, API, services) with
TEST DOUBLES (fake stand-ins):
→ isolate the unit (test ONLY it, not its dependencies)
→ FAST (no real DB/network); CONTROLLED (set up exact scenarios, including errors);
DETERMINISTIC (no external flakiness)
