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
About the Author
About the Reviewers

Mockito versus JMockit

In this recipe, we will write a simple test using JMockit that verifies the behavior of the system under test when an exception is thrown.

Getting ready

In order to profit from JMockit, you need to add it to your classpath. The following is the JMockit configuration for Gradle:

testCompile 'com.googlecode.jmockit:jmockit:1.7'

The following is how you can add JMockit to your classpath using Maven:



If you do not use @RunWith(JMockit.class), then you need to define the JMockit dependency before the JUnit one! Please refer to for more information.

Let's assume that our system under test is the tax transferring system for a given person, as shown in the following code:

public class TaxTransferer...