EasyMock vs Mockito:设计 vs 可维护性? [英] EasyMock vs Mockito: design vs maintainability?

查看:22
本文介绍了EasyMock vs Mockito:设计 vs 可维护性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此的一种思考方式是:如果我们关心代码的设计,那么 EasyMock 是更好的选择,因为它通过其期望概念向您提供反馈.

One way of thinking about this is: if we care about the design of the code then EasyMock is the better choice as it gives feedback to you by its concept of expectations.

如果我们关心测试的可维护性(更容易阅读、编写并且测试不那么脆弱,不会受到变化的太大影响),那么 Mockito 似乎是一个更好的选择.

If we care about the maintainability of tests (easier to read, write and having less brittle tests which are not affected much by change), then Mockito seems a better choice.

我的问题是:

  • 如果您在大型项目中使用过 EasyMock,您是否发现您的测试更难维护?
  • Mockito 有哪些限制(除了 endo 测试)?

推荐答案

我是一名 EasyMock 开发人员,所以有点偏心,但我当然在大型项目中使用过 EasyMock.

I'm an EasyMock developer so a bit partial but of course I've used EasyMock on large scale projects.

我认为 EasyMock 测试确实会偶尔中断.EasyMock 强制你对你所期望的做一个完整的记录.这需要一些纪律.您应该真正记录预期的内容,而不是测试方法当前需要的内容.例如,如果在 mock 上调用方法的次数无关紧要,不要害怕使用 andStubReturn.此外,如果您不关心参数,请使用 anyObject() 等等.在 TDD 中思考可以对此有所帮助.

My opinion is that EasyMock tests will indeed breaks once in a while. EasyMock forces you to do a complete recording of what you expect. This requires some discipline. You should really record what is expected not what the tested method currently needs. For instance, if it doesn't matter how many time a method is called on a mock, don't be afraid of using andStubReturn. Also, if you don't care about a parameter, use anyObject() and so on. Thinking in TDD can help on that.

我的分析是,EasyMock 测试会更频繁地中断,但 Mockito 测试不会在您希望它们时中断.我更喜欢打破我的测试.至少我知道我的发展对我有什么影响.这当然是我个人的观点.

My analyze is that EasyMock tests will break more often but Mockito ones won't when you would want them to. I prefer my tests to break. At least I'm aware of what was the impacts of my development. This is of course, my personal point of view.

这篇关于EasyMock vs Mockito:设计 vs 可维护性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆