Literate testing – extending JMock
Posted by Piotr Gabryanczyk on December 6, 2006
I have come across the following post today: http://weblogs.java.net/blog/tomwhite/archive/2006/05/literate_progra_1.html
I think it is a great idea to use natural language to simplify unit testing. I even wrote couple of similar extensions to JMock lately. I will share them soon
JMock vs EasyMock
Many developers choose EasyMock over JMock. The main argument is “JMock tests are not easy to refactor because method names are passed as a string”. I am not going to comment on that as many people already proved that good IDE can handle it easily.
What people do seem to forget is:
- JMock uses literate API,
- JMock tests are much more consistent comparing to EasyMock (you can clearly see what the expectations are)
- In JMock you can easily differentiate between expectations and stubs
- In JMock you can easily show which parameters are insignificant using ANY-like
- EasyMock produces very ugly code when expected methods declare exceptions
- EasyMock produces ugly code when expected method doesn’t return the value
Probably there is more…
Let me know what you think!
