5. Using Test Doubles with Unit Tests

We now introduce a significant piece of the unit testing approach—test doubles. Using test doubles is a way of creating a class whose behavior can be changed at runtime. These classes can be used to unit test our code much more thoroughly than we could have otherwise. Let’s look at the details of how these classes help write unit tests.

How Do Test Doubles Work?

Test doubles work by replacing real classes with an imitation class that can be created at runtime, not design time. Using this imitation class, we can change the behavior to perform any action or return any values that we want for a test. In this way, we can simulate many different situations happening to the business logic without having to go to ...

Get Reengineering .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.