如何使用 EasyMock 测试模拟调用的顺序
在 EasyMock 中很容易做到:
EasyMock.expect(service.methodCall());
但我注意到这并没有测试我执行调用的顺序,其中我正在尝试测试的一个案例非常重要。有没有办法用 EasyMock 来做到这一点?
It's easy enough in EasyMock to do:
EasyMock.expect(service.methodCall());
but I noticed that this does not test the order in which I execute the calls, which in a case that I am trying to test is very important. Is there anyway to do this with EasyMock?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
EasyMock.createStrictMock()
创建能够检查方法调用顺序的模拟。http://easymock.org/EasyMock3_0_Documentation.html
(搜索“检查模拟之间的方法调用顺序”在上面的链接中作为示例)。
You can use the
EasyMock.createStrictMock()
for creating a mock thats capable of checking the order of method calls.http://easymock.org/EasyMock3_0_Documentation.html
(search for "Checking Method Call Order Between Mocks" in the above link for examples).
如果您需要测试不同模拟对象的顺序,可以使用 EasyMock.createStrictControl() 来创建模拟,运行 replay() &
验证()
。该网站有一些方便的示例代码: http://www.michaelminella.com/testing/mock-controls-with-easymock.html(archive.org 镜像)
If you need to test the order across different mocked objects, you can use
EasyMock.createStrictControl()
to create the mocks, runreplay()
&verify()
.This site has some handy sample code: http://www.michaelminella.com/testing/mock-controls-with-easymock.html (archive.org mirror)