Which is the best isolation framework for Java? JMock, Easymock, Mockito, or other?

こ雲淡風輕ζ 提交于 2019-12-10 13:06:04

问题


I realize this has been asked before, but the last time was in mid 2008.

If you were starting a new project right now, which one would you use and why? What are their strengths/weaknesses regarding readability, usability, maintainability, and overall robustness?


回答1:


I have used Easymock earlier, but now I'm using Mockito. I found Mockito simpler as compared to Easymock. For the detailed comparison of Easymock and Mockito you can refer here




回答2:


To explain our motivation, jMock is an "opinionated" library. It's designed to guide an approach to OO design that focusses on protocols between collaborating objects. If you don't think of your systems in that way, then it's probably not your best option.




回答3:


I have been using EasyMock for some time, now. Continues to add new features that allow one to reach more of those hard-to-get-to places.

Mockito will save some lines of code for most common test cases.

Could you elaborate on your mock capability needs/priorities? Fairly broad, as stated.




回答4:


My (biased) answer would be JMockit. For a quick comparison with other mocking toolkits, see the comparison matrix.

Test code written with it should be more readable and better structured (there are example tests for side-by-side comparison). The JMockit mocking API usually requires less "uses" than other mocking APIs to write the same test. The greatest advantage, IMO, is that it doesn't force any design compromises on the code to be tested. On the downside, since JMockit relies on more advanced techniques and has more capabilities, it also has a greater potential for users to run into unexpected difficulties.



来源:https://stackoverflow.com/questions/3058410/which-is-the-best-isolation-framework-for-java-jmock-easymock-mockito-or-oth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!