Creating partial mocks
Using partial mocks generally should be considered a code smell. When writing good and clean code, you want it to be modular and follow all of the best practices, including the SOLID principles (please refer to the Introduction section of Chapter 2, Creating Mocks, for an elaborate explanation). When working with complex code, as a refactoring process, one tries to split the largest tasks into more modular ones. During that process, you may want to mock external dependencies of the system under test. You might come across a situation in which you do not want to mock the entire dependency but only a part of it while leaving the rest unstubbed. Such a mocked class is called a partial mock and creating one means that a class that you are mocking most likely does more than one thing, which is a pure violation of the single-responsibility principle.
Let's consider the example from the current chapter – the TaxService
class. It has two responsibilities:
Calculation of the...