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

Mockito versus EasyMock

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

Getting ready

In order to profit from EasyMock, you need to add it to your classpath. This is the configuration for Gradle:

testCompile 'org.easymock:easymock:3.2'

The following is how you add the EasyMock dependency in Maven:

<dependency>
    <groupId>org.easymock</groupId>
    <artifactId>easymock</artifactId>
    <version>3.2</version>
    <scope>test</scope>
</dependency>            

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 { private final TaxService taxService; public TaxTransferer(TaxService taxService) ...

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