A test double substitutes for a real collaborator and simulates its behavior during a test. Replacing a troublesome dependency can simplify automated tests and let a component be tested in isolation. section 5.4.3 section 7.3.1
Dependency injection allows a test to supply the substitute to the component under test. For example, a mock data access object can simulate database access, enabling a fast in-memory unit test instead of a test that requires a database. section 5.4.3 section 5.4.4
The same approach supports local development and component-level pipelines. A developer can run one component locally while simulating its service dependencies; in a modular monolith, module tests can substitute for other domain modules. section 5.4.5 section 6.2.5
Testing an Order Service locally
A developer runs the Order Service with its required infrastructure, such as a database and message broker, while a test double simulates the Customer Service. This avoids running every service in the application. section 5.4.5
Isolation is useful only if the substitute represents the collaborator’s API accurately. Simple, well-defined, stable APIs make collaborators easier to simulate; contract tests help verify that services implement and use the APIs expected by their clients and collaborators. section 7.3.1
Use doubles where dependencies make tests slow or difficult, but do not assume simulation replaces every real interaction. For example, testing actual third-party webhook requests may require a remote environment. Side-effect-free functions with no dependencies offer another way to simplify tests without configuring doubles. section 5.4.5 section 5.4.3








