Closed zhongyuanjia closed 1 year ago
Of course not! I suggest you to use a testing framework like goconvey, testify, and so on. Your test case is not single, it should be split into two. If you don't want to split the test case,you can use another API like ApplyMethodSeq.
The following code is valid for version 2.2.0
patches := gomonkey.NewPatches()
defer patches.Reset()
patches.ApplyMethod(val, "A", func() error { return nil })
patches.ApplyMethod(val, "A", func() error { return errors.New("test") })
val.A() // will return test error
When I upgrade to a new version, the above code reports a "patch has been exists" error
So I needed a way to bypass detection, This is the PR
Take a look at the following code