⚠️ UPDATE 12/2019: Moxiemocks is no longer actively maintained. You'll probably want to use Mockito instead - it's battle-tested, and at any rate their mocking syntax and feature set have improved since I first wrote Moxie.
Moxie is a library for creating mock objects in Java. It aims to enable prescriptive mock tests with an easy-to-use syntax:
- Concise - set up any expectation in one Java statement. Short method names, no anonymous inner classes, no need to "replay" mock objects.
- Refactorable - method name/signature changes using refactoring tools will be reflected in your tests.
- Easy - integrates with JUnit 4 to automatically create and verify mocks on your test objects. (You can still do this manually.)
Moxie is ovailable through Maven Central:
<dependency>
<groupId>org.moxiemocks</groupId>
<artifactId>moxie</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>Want to learn more? See...
- Javadoc for every public method
- Moxie by example - syntax comparison to other major mocking libraries, with a set of equivalent tests implemented in Moxie, JMock 1, JMock 2, EasyMock, Mockito
- Maven-generated site for the latest release (test coverage stats etc.)
You may also be interested in:
- An informal performance comparison of the major mocking libraries (executive summary: they all perform just fine)
- un-jmock1.rb - fugly, experimental Ruby script I wrote to do most of the donkey work of converting a client's JMock 1/JUnit 3 tests to Moxie/JUnit 4.
