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

Mockito versus JMock


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

Getting ready

To profit from JMock, you need to add it to your classpath. There are three factors that you must take into consideration when adding JMock to your project, as follows:

  • Jmock: This contains the core of JMock (pick it if you want to use TestNG)

  • jmock-junit4: This is to integrate JUnit with JMock (pick this one if you want to use JUnit 4+)

  • jmock-legacy: This allows you to create mocks of classes

The following is the JMock configuration for Gradle for a JUnit-based project:

testCompile "org.jmock:jmock-junit4:2.6.0"
testCompile "org.jmock:jmock-legacy:2.6.0"
testCompile "org.jmock:jmock:2.6.0"

The following are the JMock dependencies for Maven:

<dependency>
  <groupId>org.jmock</groupId>
  <artifactId>jmock</artifactId>
  <version>2.6.0</version>
<scope>test</scope>
</dependency...