Skip to end of metadata
Go to start of metadata

JMock is a popular mocking framework for Java. Several versions are available.

The sections below illustrate using various versions of JMock for the mocking parts of Using Testing Frameworks with Groovy.

The Item Storer Example

We are going to consider how you might use JMock as part of testing the Item Storer Example.

Here is how we can test JavaStorer using version 1.x of JMock using its JUnit 3 integration:

Here is how we can test JavaStorer using version 2.x of JMock using its JUnit 4 integration:

To make our tests a little more DSL-like, we used the following helper class with JMock 2:

  • No labels


  1. E

    I think it's important to note that JUnit4GroovyMockery is a Java class (and a Java file), and not a Groovy one. Groovy doesn't support inner classes.

  2. I've had problems with using some of the matcher from Groovy. Is I have a method which takes a class which hasn't implemented Equals (generated code), I want to specify something like this:

    This does fail with the following exception:

    Any example on using these matchers would be beneficial.