EasyMock - 如何重置模拟但保持期望?
是否可以对同一模拟对象实例重新定义特定期望?
假设我有一个验证正常的测试:
List<String> foo = createMock(List.class);
expect(foo.get(1)).andReturn("Wibble").once();
expect(foo.size()).andReturn(1).once();
replay(foo);
System.out.println(foo.get(1));
System.out.println(foo.size());
verify(foo);
然后我想做的是重置模拟,维护所有已定义的期望,但更改其中一个,说:
reset(foo);
// Redefine just one of the two expectations
expect(foo.get(1)).andReturn("Wobble").once();
System.out.println(foo.get(1));
System.out.println(foo.size());
verify(foo);
目前不起作用,因为 foo.size 未定义重置通话后。
一定是一个很好的方法来做到这一点,而不是每次都重建期望?
提前致谢
Is it possible to re-define specific expectations on the same instance of mock object?
Say I have this test which verifies OK:
List<String> foo = createMock(List.class);
expect(foo.get(1)).andReturn("Wibble").once();
expect(foo.size()).andReturn(1).once();
replay(foo);
System.out.println(foo.get(1));
System.out.println(foo.size());
verify(foo);
What I would then like to do is reset the mock, maintaining all of the defined expectations, but changing one of them, say:
reset(foo);
// Redefine just one of the two expectations
expect(foo.get(1)).andReturn("Wobble").once();
System.out.println(foo.get(1));
System.out.println(foo.size());
verify(foo);
Doesn't work at the minute as foo.size is not defined after the reset call.
Must be a nice way to do this rather than rebuilding the expectations every time?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将期望写成函数并将期望的参数作为参数传递吗?这就是我以前做过的事情。
加:返回第零个字符串,是吗?
Could you write the expectations as a function and pass the expected argument as an argument? It's what I've done on previous occasions.
Plus: return zeroth String, yes?