Chapter 2. Creating Mocks

In this chapter, we will cover the following recipes:

  • Creating mocks in code
  • Creating mocks with annotations
  • Creating mocks with a different default answer
  • Creating mocks with different default answers with annotations
  • Creating mocks with custom configuration
  • Creating mocks of final classes with PowerMock
  • Creating mocks of enums with PowerMock

Introduction

Mockito, as the name suggests, is all about working with mocks. It is worth mentioning that before you go and start mocking every class that is in your codebase, it's good to really understand the idea behind mocking and when to mock an object.

While performing unit testing, you will want to test your system in isolation. You're doing it because you want to test a part of the ...

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.