Installing Mockito

Mockito is a testing framework that allows one to stub objects, like dates, e-mail services, etc. within automated tests, to simulate the passing of time or sending of e-mails. (Mockito tutorial.)

Mockito used to provide a single jar file including all dependencies. However, since version 2.0.2 this has been replaced by using Maven and Gradle build scripts with explicit dependencies. Now Mockito and all its dependecies are loaded directly from the Maven repository.

The easiest way to use Mockito is to include mockito-all-2.0.2-beta.jar or an earlier version in the class path. This is also the way the programming assignments are using Mockito. However it is also quite easy to access the latest version (2.7.9) of Mockito using Eclipse.

In the first step, one converts the Java project to a Maven project using the "Configure::Convert to Maven" menu option of projects. It is okay to accept the default settings for the parameters.

Configure Maven project

In the second step, the dependency to Mockito is added to the Maven pom XML file:

Maven POM dependencies tab

Mockito dependency

Finally, one can see the jar files being added to the Java program:

Mockito dependencies

Now the tests can be run as usual. One does not need to execute the Maven build scripts that appear in the "run as" menu of the project.


Part of Instructions
Hubert Baumeister
October 3, 2017