O'Reilly logo

Mockito Cookbook by Marcin Grzejszczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required