Skip to main content

Test Doubles and Modern Mocking

Test isolation is the foundation of fast, reliable unit tests. When your code depends on databases, APIs, time, or external services, test doubles let you replace those dependencies with controlled substitutes—keeping tests focused, quick, and deterministic. This series teaches you how to architect tests using mocks, stubs, fakes, and spies; implement them with production-grade libraries like Moq and NSubstitute; verify that your code calls dependencies correctly; and recognize when mocking actually hurts test quality.

Over the next ten tutorials, you'll move from foundational concepts (what a test double is) through intermediate patterns (fluent mock setup, HTTP faking, time manipulation) to advanced techniques (interaction verification, spy patterns) and professional judgment calls (when a fake test implementation beats a mock, how to spot tests that over-specify behavior and become brittle). By the end, you'll write unit tests that are both rigorous and maintainable—resistant to implementation changes while still catching real bugs.

Each article includes runnable C# examples, decision tables, and a FAQ section addressing the most common gotchas developers hit when adopting modern mocking practices.

Articles in this series