【发布时间】:2014-04-18 13:19:43
【问题描述】:
正在测试的函数通过不同的输入调用函数 findByNames 并期望不同的输出。我需要使用服务 uDao 来模拟它。那么我应该写两个不同的期望吗?但它不起作用......我应该如何处理这种情况?
EasyMock.expect(uDao.findByNames(CollectionUtils.newArrayList(target1Username)))
.andReturn(CollectionUtils.newArrayList(target1Group)).once();
//code in between
EasyMock.expect(uDao.findByNames(CollectionUtils.newArrayList(target1Username, ownerUsername)))
.andReturn(CollectionUtils.newArrayList(target1Group, ownerGroup));
/*target1Username, ownerUsername are strings and target1Group,
ownerGroup are of class UserGroup
*/
【问题讨论】:
-
也许我可以使用 EasyMock.expect(userGroupDao.findByNames(EasyMock.isA(List.class))).andReturn(CollectionUtils.newArrayList(target1Group, ownerGroup));但这显示错误,因为 findByNames 期待 Collection
-
“但它不起作用”是什么意思?您收到错误消息吗?
-
junit.framework.AssertionFailedError: java.lang.AssertionError: 意外的方法调用 findByNames([elementsuser1@elements.com, owner@ owner.com]): findByNames([elementsuser1@elements.com, owner@owner.com]): 预期:1,实际:0 -
我不明白这个错误想说什么......
-
在调试时我注意到 findByNames 的第一遍工作正常......但是对于 findByNames 的第二个期望,调试器抛出错误,甚至无法进入函数 findByNames
标签: unit-testing junit easymock