Search code examples
javaunit-testingjmockjmockitmockito

Does JMockit have any drawbacks at all?


This comparison shows, that JMockit has several advantages over other frameworks.

Are there also any advantages that one of the others (JMock, EasyMock, Mockito, Unitils, PowerMock + Mockito/EasyMock) has over JMockit?


Solution

  • Three drawbacks:

    • You must use a Java agent to do bytecode instrumentation.
    • You can't use the signed junit.jar file shipped with Eclipse.
    • You have to learn a mock API. (In contrast to a stub object)

    You can always discuss if it's a good thing to be able to mock a final class like JMockit can. Unless it's legacy code, refactoring is usually a better alternative.

    With IDEs like Eclipse, I find myself using tool support to generate stubs inside the test class more frequently than mocking (JMockit, Mockito, etc.) in the recent time. The advantage with this approach is that it's very simple. This is especially nice when you have a team with many developers and some of them don't like testing and have little motivation to learn a mocking framework. Also, stub implementations don't have framework limitations!

    If you're open for stubbing as an alternative, you should check out Robert C. Martin's blog about mocking and stubbing here and here

    Else, it looks very good! Although I have only experience with JMock, EasyMock and basic knowledge with JMockit.