如何断言 Go 中使用特定参数调用了模拟?

问题描述 投票:0回答:1

假设我有一个这样的测试

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?

我想知道我是否需要为此目的添加一个额外的库

unit-testing go mocking
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.