【问题标题】:How to test the order of mocked calls using EasyMock如何使用 EasyMock 测试模拟调用的顺序
【发布时间】:2010-09-18 05:00:57
【问题描述】:

EasyMock 很容易做到:

EasyMock.expect(service.methodCall());

但我注意到这不会测试我执行调用的顺序,这在我尝试测试的情况下非常重要。有没有办法用 EasyMock 做到这一点?

【问题讨论】:

    标签: java unit-testing testing mocking easymock


    【解决方案1】:

    您可以使用EasyMock.createStrictMock() 创建一个能够检查方法调用顺序的模拟。

    http://easymock.org/EasyMock3_0_Documentation.html

    (在上面的链接中搜索“Checking Method Call Order Between Mocks”作为示例)。

    【讨论】:

    【解决方案2】:

    如果您需要测试不同模拟对象的顺序,可以使用EasyMock.createStrictControl() 创建模拟,运行replay() & verify()。

    这个网站有一些方便的示例代码:http://www.michaelminella.com/testing/mock-controls-with-easymock.html (archive.org mirror)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多