Book Image

Mockito Cookbook

By : Marcin Grzejszczak
Book Image

Mockito Cookbook

By: Marcin Grzejszczak

Overview of this book

Table of Contents (17 chapters)
Mockito Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introduction


In this chapter, we will take a look at other mocking frameworks that are quite well known in the Java world. The idea of this chapter is not to state whether one mocking framework is better than Mockito, but to point out differences in both their syntax and approach.

Remember that the examples presented in this chapter are very simple and do not show all of the possible ways of using the mocking frameworks, since you could write books about any of them.

Before moving forward, it's worth mentioning the difference between a strict mock and a non-strict one:

  • Strict mock: This is a mock that will fail the moment anything differs from the expectations. In other words, if you expect your mock to call some methods and that doesn't happen, then your test will fail.

  • Non-strict mock: This is a mock that will ignore any methods that were expected and were not executed. Your test won't fail even when an unexpected method is called. Mockito's mocks are non-strict.

It's important to understand...