假设我有一个这样的测试
func TestSomeFn(t *testing.T){
t.Run("the fn is called with x when someFunc is called with y", func(t *testing.T){
mockFn := new(MockFn) // this is a mock for a function utilized inside of someFunc
response := true
expected := "expected-value"
mockFn.On("method", mock.Anything).Return(response, nil)
res, err: = SomeFn(mockFn, x)
require.NoError(t, err)
assert.Equal(t,expected,res)
}
}
我应该如何编写该行来断言使用某些参数调用了mockFn?
我想知道我是否需要为此目的添加一个额外的库
假设您正在使用github.com/stretchr/testify/mock,您可以定义自己的模拟对象或使用
mock.MatchedBy
。