cch123 / supermonkey

Patch all Go functions for testing
MIT License
249 stars 17 forks source link

Suggestions on how to best integrate with Testify? #21

Open Marakai opened 1 year ago

Marakai commented 1 year ago

To my amazement and joy this worked from the outset on an M1 Mac in Goland with Go 1.19.1! Unlike another package I won't name.

My question now is, where the best place would be to integrate with Testify as the test framework?

Having to set up the mock in every single package that uses my to-be-monkeyed methods/funcs would be highly annoying (doable, but annoying).

Unfortunately Testify doesn't have a "super-test-setup" that you can do once and every Suite setup receives. At least as far as I saw in the doco.

Any ideas?

Marakai commented 1 year ago

Note: I've now embedded a helper function to set up patchguards in SetupSuite() and unpatch in TearDownSuite(). That seems to work. Now I'm looking for a way to sequentially patch in different monkeys. As in, first call should call fakeMethod1(), second call should call fakeMethod2(), and so on.

Something like sm.PatchSequence(patchMe func(), returnMe ...func())

cch123 commented 1 year ago

monkey patch is still a hack tool to do the test stuff, it has too many limitations, eg. cannot run tests in parallel, broken compatibility when update happen .etc

we only use it to do the patch when the mock is too hard to write