
Overview
EasyMock provides Mock Objects for interfaces in JUnit tests 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 MIT license. Development and downloads are hosted on SourceForge.
Changes
- 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.