Sunday, March 23, 2008

Mockito: A Test Spy implementation

What's the best Mock Framework that you think?

Some people say: "EasyMock, sure!".

Others: "JMock!".

Wait wait wait! You be heard about Test Spy?

Mockito is an implementation of Test Spy, but doesn't use this metaphor at all. Created by Szczepan Faber, aiming to become the best mocking framework!

So, what Mockito do?

Like expect-run-verify library, as EasyMock and Jmock, Mockito offers simpler and more intuitive approach. You ask questions about interactions after execution. Using other libraries, you often look irrelevant interactions.

Mockito has similar syntax to EasyMock, therefore you can do refactor safely! Differ by notion of expectations, there is only stubbing or verification.

Some other features:

* Mocks concrete classes as well as interfaces
* Allows flexible verification in order (e.g: verify in order what you want, not every single interaction)
* Supports exact-number-of-times and at-least-once verification
* Flexible verification or stubbing using argument matchers (anyObject(), anyString() or refEq() for reflection-based equality matching)
* Allows creating custom argument matchers or using existing hamcrest matchers
* Verification errors are clean - click on stack trace to see failed verification in test; click on exception's cause to navigate to actual interaction in code. Stack trace is always clean.
* Little annotation syntax sugar - @Mock
* Single-jar distribution mockito-all-1.2.jar includes cglib, objenesis and java source
* Zip distribution contains all jars, javadoc and source.


Handerson Frota said...

Olha ai :D finalmente :D rsrsrs

Ta massa o post, parabéns.

PS: Dica: Troca essa funcionalidade de post pq é meio chato :P sério rsrsr

Rafael Ponte said...

Well, good post Rene, but where is code samples of this framework? :)

You could show us some code sample!

renearaujo said...

Sure, in next post :) thanks!

Anonymous said...

Thanks for the helpful post. When I was looking for a content management system I found that these guys were the best.

stacy said...

Cool blog. If you need a wireless home theatre system then this is a great resource.

Brian said...

I was facing addiction and wanted to go to a drug rehab new mexico. These guys are the best and the really know how to help a person grow.

Joan Brown said...

Great post! I've also found that doing web design freelance work has helped me succeed.

stacy said...

I like this blog lots of useful info. I think this is great info on a home movie theater system if you need one.

Tina said...

Thanks for the info. It can be hard figuring out from all the internet marketing firms which one will work for you. Do your research and I’m sure you’ll find someone that works.