How to make writing unit tests fun again (Mockito to the rescue)

Last year after finally getting fed up with mockobjects, I decided to have a look around for a better alternative. Having used EasyMock in the past, I knew there was at least one better framework. But after talking to other Atlassians I was pointed to Mockito (which started as a fork of EasyMock). Mockito finally got rid of the record-replay concept which was annoying me so much while using EasyMock, and after going through the docs and playing a little bit around with it, I was convinced pretty quickly that this is the best mocking framework currently available for Java.

Why is it better?

I gave a presentation on Mockito a while ago which included a short comparison with other mocking frameworks. Here is a brief summary of the improvements over other mocking frameworks:

Code improvements

A couple of things I noticed while doing the conversion:

Writing tests is fun again

The biggest improvement of all for me is the fact that I actually have fun again writing unit tests. Well, there are definitely more fun things than writing tests, but at least I don’t have to shudder and get goosebumps when I have to write a unit test 🙂
And from the feedback I got from the rest of the Confluence team everyone else feels the same, which should eventually lead to people writing more tests again and actually maintain them.

Consider moving to Mockito

I know that a couple of people on other teams here at Atlassian aren’t to happy with their current mocking framework either. So if you think about moving give Mockito a shot. We are using it now for more than two months for Confluence and we haven’t discovered any issues yet.

Exit mobile version