
Overview
EasyMock provides Mock Objects for interfaces (and objects through the class extension) by
generating them on the fly using Java's proxy mechanism. Due to EasyMock's unique style of
recording expectations, most refactorings will not affect the Mock Objects. So EasyMock is
a perfect fit for Test-Driven Development.
EasyMock is open source software available under the terms of the Apache 2.0 license. Source code and downloads are hosted on SourceForge. Issue tracking is done at Codehaus.
Changes
- 2011-11-08: EasyMock 3.1 is available. Lots of bug fixes.
- 2011-11-08: EasyMock 3.1 Class Extension is available. Just following EasyMock versionning. Still deprecated.
- 2010-05-08: EasyMock 3.0 is available. Perform class mocking directly. EasyMock 1 classes removed.
- 2010-05-08: EasyMock 3.0 Class Extension is available. Now deprecated. Only a proxy over EasyMock to provide backward compatibility.
- 2009-12-20: EasyMock 2.5.2 Class Extension is available. EasyMockSupport implementation for class extension.
- 2009-12-17: EasyMock 2.5.1 Class Extension is available. Now under Apache 2.0 license.
- 2009-12-15: EasyMock 2.5 Class Extension is available. More easier to create partial mocks using
IMockBuilder. Also serializable mocks and OSGi bundled.
- 2009-09-12: EasyMock 2.5.2 is available. Capture bug for stubs fixed. New EasyMockSupport class.
- 2009-06-17: EasyMock 2.5.1 is available. Now under Apache 2.0 license.
- 2009-05-24: EasyMock 2.5 is available. Better multithreading, capture and compatibility with previous version.
OSGi bundle. New delegation feature. Improved error message.
- 2008-08-30: EasyMock 2.4 Class Extension is available. Fully compatible with EasyMock 2.4. However, it is
not possible to serialize class extension mocks yet.
- 2008-07-02: EasyMock 2.4 is available. Allows mock serialization, parameter capture,
thread-safe mode and to change mock type.
- 2007-12-26: EasyMock 2.3 Class Extension is available. Fully compatible with EasyMock 2.3 and allows a constructor
to be called on partial mocking.
- 2007-07-09: EasyMock 2.3 is available. Allows mock naming and adds new matchers for Comparable/Comparator.
- 2007-04-12: EasyMock 2.2.2 Class Extension is available. Improved performance and memory usage, support
for JRockit and GCJ, possibility to extend support to other JVMs.
- 2006-04-17: EasyMock 2.2 is available. It allows callbacks to return values and to throw exceptions,
and extends replay(), verify() and reset() to accept multiple mock objects as arguments.
- 2006-04-17: EasyMock 2.2 Class Extension is available.
- 2006-04-08: EasyMock 2.1 Class Extension is available. Its self-tests are updated to JUnit 4.
- 2006-03-19: EasyMock 2.1 is available. It allows callbacks, fixes a bug and introduces
earlier failing if unused matchers were specified.
- 2005-12-24: EasyMock 2.0 is available. It has a lot of new features, among them
refactoring-safe per-argument matchers and a new syntax that relies on Java 5.0. It has 100% unit test
coverage, and the release includes updated documentation and javadoc.
What is a Mock Object?
Unit testing is the testing of software units in isolation.
However, most units do not work alone, but they collaborate
with other units. To test a unit in isolation, we have to
simulate the collaborators in the test.
A Mock Object is a test-oriented replacement for a collaborator.
It is configured to simulate the object that it replaces in a simple way.
In contrast to a stub, a Mock Object also verifies whether it is used as expected.
Tim Mackinnon, Steve Freeman and Philip Craig pioneered the concept of Mock Objects, and coined the term.
They presented it at the XP2000 conference in their paper
Endo Testing: Unit Testing with Mock Objects.
A reworked version of the paper is published in the book Extreme Programming Examined
(Addison-Wesley).
EasyMock has been the first dynamic Mock Object generator, relieving
users of hand-writing Mock Objects, or generating code for them. It was
presented for the first time at OOPSLA 2001.