After using EasyMock for several months I found Mockito. Yeah, the name sounds terrible in Spanish: little snot. It will be hard for me to tell spanish developers mockito features avoiding laughs. Guys, be careful with names next time 🙂
Mockito API is so cool that you no longer have to care if you're using a mock or a stub. You just use test doubles the way you need them and nothing more. Record/Replay metaphor is no longer used. The framework knows when are you writing the arrange, the act and the assert steps.
See how easy it is to mock out a void method (EmailAddress is a JPA Model):
@Test EmailAddress emailMock = mock(EmailAddress.class); Persistor<EmailAddress> persistor = new Persistor<EmailAddress>(); persistor.Save(emailMock); verify(emailMock).save(); }
Check out some examples: http://schuchert.wikispaces.com/Mockito.LoginServiceExample
My favorite mock frameworks so far are Mockito for Java and Rhino.Mocks for C#. They share pretty much all these nice features.