【问题标题】:How to assert that mocked method calls happen in-order with testify?如何断言模拟方法调用与作证按顺序发生?
【发布时间】:2016-10-22 18:02:06
【问题描述】:

AssertExpectations 的文档说“AssertExpectations 断言使用 On 和 Return 指定的所有内容实际上都按预期调用。调用可能以任何顺序发生。”如果我想断言某些调用按顺序发生怎么办?

gomock 对此有*Call.After(*Call),但我在作证中看不到任何类似的东西。有没有办法,或者我应该只使用 gomock?

【问题讨论】:

    标签: unit-testing go mocking testify


    【解决方案1】:

    Testify 目前不支持此功能,但在本期 https://github.com/stretchr/testify/issues/741 中进行了跟踪。

    Testify 的 mock.Mock 对象通过 Calls 属性 (https://pkg.go.dev/github.com/stretchr/testify/mock#Mock) 提供对有序调用的访问,您可以使用它自己构建此功能。

    【讨论】:

    猜你喜欢
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    相关资源
    最近更新 更多