Home arrow Blog

JUnit and EasyMock Refcard

RefcardWell, it’s finally here! The JUnit and EasyMock Refcard is available at DZone. You can download it here: http://refcardz.dzone.com/refcardz/junit-and-easymock. This Refcard covers JUnit and EasyMock in detail, both in concept and at the API level. If you have never used JUnit or EasyMock or are seasoned veterans with them both, this card should be a valuable tool for you to refer to when writing unit tests. I wanted to take a minute to thank Jill Tomich for her help threw the process. This is my first formally published work and she was a big help! Let me know what you think of the new Refcard in the comments!

2 Responses to “JUnit and EasyMock Refcard”

  • Al Scherer responded:

    Hi Michael,

    I submitted a comment to DZone about this RefCard. It’s great and exactly what my team is using but your JUnit 4 example takes an outdated approach to handling expected exceptions (ref: test method testBadResultsBar).

    JUnit 4 offers the following syntax to test for expected exceptions:
    @Test(expected=NullPointerException.class)

    Use that annotation and you don’t need any of the try-catch code for validating expected exceptions. The test will fail if you don’t throw that exception. That reduces the testBadResultsBar method down to one single line where you invoke foo.bar.

    Regards,
    Al Scherer

  • Al Scherer responded:

    Hello again,

    One last note: I posted one final note on DZone about defining expectations of void methods.

    I also thought there wasn’t a discussion of createStrict vs createNiceMock but - my mistake - I just didn’t catch it first time through.

    Regards,
    Al Scherer

Add your own comment...