Mocking the DI Container vs Specific Dependencies in Integration Tests.
Updated Apr 28, 2026
Short answer
In Integration Tests, you spin up the entire application DI container but override specific external dependencies (like databases or APIs) with stubs.
Deep explanation
Unlike unit tests (where you mock everything explicitly), integration tests rely on the real DI container to ensure the application wires together correctly. You use features like ConfigureTestServices to replace only the IHttpClientFactory or IDbContext with a test double, leaving the rest of the graph intact.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro