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

<dependency>
  <groupId>com.googlecode.jmockit</groupId>
  <artifactId>jmockit</artifactId>
  <version>1.7</version>
  <scope>test</scope>
</dependency>            

Note

If you do not use @RunWith(JMockit.class), then you need to define the JMockit dependency before the JUnit one! Please refer to http://jmockit.googlecode.com/svn/trunk/www/gettingStarted.html ...

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