Summary
EasyMock is a dynamic mock object generator: It helps write unit tests by generating mock objects on the fly using Java's proxy mechanism. A recent java.net article introduces EasyMock2, and provides a tutorial on testing with mock objects.
While writing unit tests for simple classes and interfaces is trivial, in most real-world systems classes and interfaces do not exist in isolation, but instead rely on other system components to operate. Testing such interrelated components is much more difficult and error-prone.
Mock objects provide a technique to test components of a complex system in isolation. EasyMock was the first tool to implement the concept and help generate mock objects, and is still the most popular. In a recent java.net article, Getting Started with EasyMock2, Ralf Stuckert introduces testing with mock objects, and highlights new features in EasyMock2, such as:
- No more need for a dedicated control object.
- Heavy usage of generics eliminates casts.
- New matcher API allows fuzzy parameter matching.
- Check call order of more than one mock.
- Dynamically respond to mock method calls.
What's your experience with EasyMock and mock objects-based testing?