An out-of-process dependency runs outside the application's execution process and provides access to data or services not yet held in application memory. Databases and file systems are typical examples. Because tests communicate with them across a process boundary, they are usually slower than in-memory dependencies. section 2.1 section 2.4
Distinguish the dependency's process location from whether tests can interfere through it:
- A database is both out-of-process and shared when tests can modify the same instance and affect one another. section 2.1
- A database started in a Docker container for each test run remains out-of-process but is not shared between test runs. section 2.1
- A read-only product API is out-of-process but not shared because tests cannot modify its returned data. section 2.2
- A shared dependency can also remain inside the process, such as a reused singleton or static mutable field. section 2.2
Out-of-process dependencies shape the boundary between unit and integration testing. Tests that reach a database or other shared dependency lose speed or isolation; replacing that dependency with a test double can preserve both. Integration tests retain selected real dependencies to verify controllers and system-level integration, while unit tests cover domain logic and algorithms. section 8.1 section 8.8
Database-backed customer test
If one test creates a customer in a shared database while another deletes it during setup, parallel execution can produce a failure unrelated to production-code correctness. Running such tests sequentially or isolating the database instance removes that interference, but direct database communication still carries a speed and maintenance cost. section 2.1 section 2.4
Figure 2.5. The relation between shared and out-of-process dependencies. An example of a dependency that is shared but not out-of-process is a singleton (an instance that is reused by all tests) or a static field in a class. A database is shared and out-of-process—it resides outside the main process and is mutable. A read-only API is out-of-process but not shared, since tests can’t modify it and thus can’t affect each other’s execution flow.
Use this relation map to compare shared and out-of-process dependencies, including databases, read-only APIs, singletons, and static fields. section 2.2
