考虑 Go 中的这个单元测试文件。我正在使用github.com/stretchr/testify/mock
包。
type Person struct {Name string; Age int}
type Doer struct { mock.Mock }
func (d *Doer) doWithThing(arg Person) {
fmt.Printf("doWithThing %v\n", arg)
d.Called(arg)
}
func TestDoer(t *testing.T) {
d := new(Doer)
d.On("doWithThing", mock.Anything).Return()
d.doWithThing(Person{Name: "John", Age: 7})
// I don't care what Age was passed. Only Name
d.AssertCalled(t, "doWithThing", Person{Name: "John"})
}
该测试失败,因为当我没有通过年龄时在比较中testify
使用。Age: 0
我明白了,但我想知道,我如何断言通过的部分论点?我希望这个测试能够通过Age
,只要Name = John