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.
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" ...