Unit testing
You learned about the basics of unit testing in the introduction section. Now let’s go a bit deeper. One of the most contentious aspects of unit testing is how isolated they must be. Let’s look at this point in more detail.
How isolated should unit tests be?
There are two sides to this debate, as described in the following bullets:
- The traditional approach to writing unit tests is to not isolate them from their dependencies. In this approach, you are testing both the MUT and its dependencies. There could be a bug in one of the dependencies that would make the test fail. This can make it harder to track down the issue since you have more places to look. But you should have tests for just those dependencies too. However, each test should be isolated from other tests.
- The more modern approach to isolating unit tests involves separating the MUT from its dependencies by replacing them with test doubles. This removes any influence on the...