The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

srinipenchikala (1) [Avatar] Offline
#1
Hi,
I have recently purchased the book and I am reading chapter 3. Chris talks about the mock object testing frameworks EasyMock and jMock (there is also rMock) which are JUnit extensions. Chris says that he prefers jMock over the other frameworks. I am new to mock testing, I was wondering if you anyone has any good (or not so good) experiences with these or any other mock object testing frameworks.

We are looking to standardize on a mock test framework at my company so any feedback on this will be greatly appreciated.

Thanks
Srini
ceracm (113) [Avatar] Offline
#2
Re: Mock object testing frameworks
Srini,

I would try jMock and easyMock and see, which one you like the most.
You could, for example, try rewriting some of the jMock tests from the book using easyMock.
Its always best to "try before you buy".


Chris
tilia (1) [Avatar] Offline
#3
Re: Mock object testing frameworks
Hi,

I have used rMock (earlier versions than the one that is actual right now, I guess it is even better nowadays) before, and was pretty happy with it. That was the first mock object testing framework I have ever used, and it did not take me a long time to figure out how to use it in a proper way. After being reserved towards the framework itself and not too interested in test driven development almost at all at start, after just a few months I became strong believer in TDD and agile methods, because all about them felt so logical and natural to me. I liked rMock, and could use it with not so much effort and with a great final benefit.

I work as an IT consultant, and recently I got to be a part of the team that works on a very cool project, in a similar setup as I am used to work in (Scrum, TDD etc), but they are using jMock. I thought, no problem, that is just an another framework, supposedly similar to rMock.
After three days into using it, my blood pressure became seriously heightened. What happened was that I refactored a lot of code that got under my hands, because the original design contained some serous flaws.

And then - I had to refactor tests. I am using Eclipse as IDE. With rMock, refactoring the tests was a charm; with jMock, it was a nightmare. The names of methods to be called, when setting up the expectations, are hardcoded, and since I did a lot of changes, nothing was up to date anymore, and I even was not able to get the help from Eclipse while refactoring. After DAYS, not hours of refactoring (I expected hours, based on the similar experience with rMock) I am done, but I am seriously discussing with my project members to leave jMock behind, test EasyMock or rMock (I am the only one that has any experience with anything but jMock), and switch to using one of them. Refactoring is not something that happens rarely. It is a phase of iterative development, and in my experience it is too tedious and frustrating to have jMock in your way during that phase.

I agree with Chris. If I were you, I would write a few tests in all of the mentioned frameworks, and some code on top of that. See how that feels.
As the next step of the evaluation, I would change the code a bit, esp. method names, introduce few new objects; and then I would try to refactor the written tests...

I would give my vote to rMock any day, but I think you should try and see what suits you personally. Each of those frameworks has advantages and drawbacks. I did not want to go into the long story about them (there is a lot of things written about all of those frameworks on the net and in various books), but rather give you the reason why I would never opt for jMock.

Good luck!

Jelena.