1.mock 函数
1.mock 方法 (interface)
type Student struct {}
func (s Student) Interesting(prodName string) bool{
return true
}
func testFunc(prodName string) bool{
st := &Student{}
result := st.Interesting(prodName)
if false == result {
fmt.Println("Student like product ", prodName)
}
return result
}
测试:
func Test_testFunc(t *testing.T) {
stu := Student{}
patch := ApplyMethod(reflect.TypeOf(stu), "Interesting", func(Student, string) bool {
return true
})
result := testFunc("pen")
So(result, ShouldEqual, true)
patch.Reset()
fmt.Println("CompareInt test success")
}