Piotr Gabryanczyk’s Blog

Java, Refactoring, AOP, Spring, DDD, TDD, etc.

  • Blogroll

    • I have joined Anti-IF Campaign

Literate testing – extending JMock

Posted by Piotr Gabryanczyk on December 6, 2006

I have come across the following post today: http://weblogs.java.net/blog/tomwhite/archive/2006/05/literate_progra_1.html

I think it is a great idea to use natural language to simplify unit testing. I even wrote couple of similar extensions to JMock lately. I will share them soon :)

JMock vs EasyMock

Many developers choose EasyMock over JMock. The main argument is “JMock tests are not easy to refactor because method names are passed as a string”. I am not going to comment on that as many people already proved that good IDE can handle it easily.

What people do seem to forget is:

  • JMock uses literate API,
  • JMock tests are much more consistent comparing to EasyMock (you can clearly see what the expectations are)
  • In JMock you can easily differentiate between expectations and stubs
  • In JMock you can easily show which parameters are insignificant using ANY-like
  • EasyMock produces very ugly code when expected methods declare exceptions
  • EasyMock produces ugly code when expected method doesn’t return the value

Probably there is more…

Let me know what you think!

About these ads

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

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: