Posts Tagged 'mockito'

Java Mocking Frameworks Comparison

I found a very nice comparison of mocking frameworks for Java/JVM. If you already have a basic understanding about mocking and are looking for a good framework with easy to learn syntax this site will definitely be helpful.

However my favourite is Mockito, which comes with a very intuitive syntax and allows mocking by stub methods. Let’s say you have a class Foobar with a public method int callMe(String s) to stub the method use the following code:

Foobar mockedFoobar = mock(Foobar.class);

That’s all, just two lines of code and you successfully mocked a method without complicated inheritance strategies :)