EasyMock 3
By Henri Tremblay on Sunday, September 13 2009, 00:57 - Java - Permalink
I've been thinking about EasyMock 3 for a while now. I'm starting to know what I'll put in there. So it's time for a little post about my roadmap just to ask the world what there think about it.
Merge EasyMock and EasyMock Class Extension
Originally, it was thought that mocking classes was caused by bad design. Years have passed and we now know that there are reasons that justify class mocking. Mainly legacy code and base class testing (where the tested class has mocked methods).
Also, even if we tried to make it as painless as possible, it can be annoying to juggle with EasyMock and EasyMock CE imports. So I would like to merge the two projects. However, I also have some requirements:
- Be able to desactivate class mocking using EasyMock properties
- Be able to mock interfaces without having cglib in dependencies
Mock private, final and static methods (and final classes)
This requires class instrumentation. So it's not that easy to do. The two possibilities are to have dedicated test runners for the main test frameworks (JUnit and TestNG) or to have JVM class instrumentation. Requirements are:
- It should be an add-on over EasyMock normal behavior and totally optional
- No test framework should be in dependency. This probably means that there should be dedicated a project for each test frameworks.
Shorter tests
The new EasyMockSupport is a little bit about that. But it want to do more to reduce the code needed to use EasyMock. This might also require dedicated test runners. Requirement:
- Be backward compatible with EasyMock 2
Get rid of EasyMock 1 code
Java 5 is now used pretty much everywhere so everyone can use EasyMock 2 now. To clean the code, I want to remove the compatibility with EasyMock 1.
Annotations
I'm not a big fan of it but sometimes it can be useful to have test annotations on your business code. For instance to create mocks on all dependencies of an object at once. The requirements are:
- The business code should only have annotations in dependency. No EasyMock code
- It should be flexible enough allow strict and nice mocks to be created
- If possible, EasyMock should work without the annotation dependency
Easier partial class mocking
I would like to provide a set of helpers to make partial class mocking easier.
Hamcrest and assertThat kind of matcher
These seem to get popularity so it would be nice to be able to have matchers using this syntax.
Be able to mock equals, toString and hashCode
The default behavior is a good thing most of the time. However, Being able to mock these two methods can be useful once in a while. So I think we should be able to overload the default.
Conclusion
As you can see, it's a pretty big roadmap. So I don't think everything will make it in the first version. Merging projects and getting rid of EasyMock 1 will be a good start.
What do you think?


Comments
IMHO merging is a very good idea - I've seen and used EasyMock in several projects, none of them without class extensions. No tool / framework should enforce/assume good design since good design is nearly non existent in practice.
+1 as well for all the other features
P.S. I will add this information to EasyMock @ wikipedial...
+1 for all the other features too, but merging EasyMock CE with the base would REALLY be the biggest improvement. My experience is the same as Sebastian, and the current split just leads to confusion and frustration, especially now that EasyMock CE is falling behind with vanilla EasyMock in version and features.
When you release the next version of EasyMock, please also include the source files of the unit tests, and not only the clover report.
This would make for an interesting sample of unit testing, and more importantly, every locale copy of EasyMock would be self-contained.
Thanks for your feedback. In fact, test sources are included in the packaging. They are in the test jar beside the compiled classes, not in a separated jar.
any clues when easymock 3 would be released?
Quite soon in fact. Possibly this week. With not all the features I was planning but the most important are there.
+1 allow to use Hamcrest Matchers directly, now that CE is integrated
Thank you for the great work!