哪个是最好的 Java 隔离框架? JMock、Easymock、Mockito 或其他?

发布于 2024-09-06 03:19:00 字数 106 浏览 3 评论 0原文

我知道以前有人问过这个问题,但最后一次是在 2008 年中期。

如果您现在要开始一个新项目,您会使用哪一个,为什么?它们在可读性、可用性、可维护性和整体稳健性方面的优点/缺点是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寄离 2024-09-13 03:19:01

我已经使用 EasyMock 一段时间了。继续添加新功能,让人们能够到达更多难以到达的地方。

Mockito 将为最常见的测试用例保存一些代码行。

您能否详细说明您的模拟能力需求/优先事项?如前所述,相当广泛。

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.

寒尘 2024-09-13 03:19:01

我的(有偏见的)答案是 JMockit。要与其他模拟工具包进行快速比较,请参阅比较矩阵

用它编写的测试代码应该更具可读性和更好的结构(有用于并排比较的示例测试)。 JMockit 模拟 API 通常需要比其他模拟 API 更少的“使用”来编写相同的测试。在我看来,最大的优点是它不会强制对要测试的代码进行任何设计妥协。不利的一面是,由于 JMockit 依赖于更先进的技术并拥有更多功能,因此用户遇到意想不到的困难的可能性也更大。

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.

指尖微凉心微凉 2024-09-13 03:19:00

我之前使用过 Easymock,但现在我使用 Mockito。我发现 Mockito 比 Easymock 更简单。有关 Easymock 和 Mockito 的详细比较,您可以参考此处

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

最好是你 2024-09-13 03:19:00

为了解释我们的动机,jMock 是一个“固执己见”的库。它旨在指导面向对象设计的方法,该方法侧重于协作对象之间的协议。如果您不以这种方式考虑您的系统,那么它可能不是您的最佳选择。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文