A managed dependency is an out-of-process dependency fully controlled by the application and accessible only through it. Because external clients cannot observe its interactions, those communications are implementation details; the dependency’s final state is what matters. section 8.2 section 8.8
Use the classification to choose an integration-testing strategy:
- Use a real instance of a managed dependency, such as an application database, rather than mocking its interactions. section 8.2
- Run the integration test through every application layer that works with the dependency, then verify its resulting state independently of the input parameters. section 8.8
- Treat an externally visible portion of a dependency as unmanaged: mock that portion, while testing the privately controlled remainder through its final state. section 8.8
- Inject managed dependencies explicitly, but use concrete classes; reserve interfaces for unmanaged dependencies or genuine abstractions with multiple implementations. section 8.4
Testing a database-backed email change
Create a real database, insert a user and company, execute the email-change scenario, and assert the updated email in the database. Mock the message bus separately and verify its interaction, because other systems observe messages sent through it. section 8.3
Figure 8.5. Treat the part of the database that is visible to external applications as an unmanaged dependency. Replace it with mocks in integration tests. Treat the rest of the database as a managed dependency. Verify its final state, not interactions with it.
Use the figure to distinguish an externally visible database surface, which is treated as unmanaged, from the privately controlled remainder, whose final state is verified. section 8.2
