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 ...
Get Mockito Cookbook 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.