【发布时间】:2016-04-16 05:31:01
【问题描述】:
在单元测试代码中同时使用模拟对象和假对象可以吗?
例子
when(computationHelper.someMethod()).thenReturn(stringGrid.writeCell(rowNum,colNum,value));
其中的computationHelper 是模拟对象,而stringGrid 是我自己的实现和一个假对象。
【问题讨论】:
-
这很好,但是模拟的整个想法是将组件从类依赖链中隔离出来,因此将假对象与其耦合似乎不正确
-
没有禁止它的规则。我会确保我的模拟对象在变量名中有
mock。
标签: java unit-testing mocking mockito