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
- What Are Test Doubles in C# Unit Testing
- Mocking in C# Unit Tests: Getting Started with Moq
- Test Doubles vs Mocks: Understanding Stubs Fakes and Spies
- NSubstitute Tutorial: Fluent Mocking for C# Unit Tests
- Verifying Interactions with Mocks in C# Unit Testing
- Mocking HTTP Requests in C# Unit Tests: HttpClient Testing
- Mocking Time and Dates in C# Unit Tests
- Advanced Mock Verification Patterns in C# Testing
- When to Use Fakes Over Mocks in C# Unit Testing
- Avoiding Over-Mocking: Best Practices for Maintainable Tests