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);
when(mockedFoobar.callMe("bla")).return(42);

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

Advertisements

2 Responses to “Java Mocking Frameworks Comparison”


  1. 1 waywalker1 August 6, 2009 at 9:33 pm

    Some new thing in java programming world: Domain Driven frameworks.
    http://www.javaneverdie.com/java-frameworks/java-domain-driven-frameworks-review/

  2. 2 Adarsh Thimmappa March 13, 2012 at 8:07 am

    Try JMockit and let me know. And, it’s much more powerful too. It purely depends on what all things you are looking for from mocking perspective. Anyways, happy mocking.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: