Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] Recent experience with mocking

rakesh mailgroups

2008-01-12

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,

I was involved in a project recently where JMock was used quite heavily. Looking back, here's what I found:

1. The unit tests where at times unreadable (no idea what they were doing).
2. Some tests classes would reach 500 lines in addition to inheriting an abstract class which also would have up to 500 lines.
3. Refactoring would lead to massive changes in test code.


I then read Martin Fowlers article about Mocks.

I then realised why the last project had the above behaviours - the mocks were used to write tests that verified the implementation of the methods/classes under test. Traditionally, unit testing was not concerned with how something was done, just that the expected output was returned.

So now my opinion has swung back to basics - test the expected outputs of the method/class under test and use mocks to conveniently stub collaborators and relax the expectations on these classes.

I understand BDD is about testing the implementation, but then how do you prevent the issues above? Does anyone else have experience of what I am talking about? Did the project do something completely wrong anyway?

Any advice appreciated,

Cheers

R


©2008 gg3721.com - Jax Systems, LLC, U.S.A.