Firstly, I love this library so much! Hooray! Thanks for sharing! <3
I'm using suite.Suite and mock.Mock and I have test suites where a number of tests share almost identical mocks, differing only where test-case-specific calls are mocked to fail (in order to test different failure conditions), e.g.
// something most of my `func Test...()`s need
suite.thing.On("DoSomething").Return(nil)
// image there are a dozen of those
// something just 1 or 2 of my `func Test...()`s need
suite.thing.On("DoSomething").Return(errors.New("something bad"))
The subject under test hits many functions like this, so I feel it is important for test confidence that I mock them all and assert that they are being called as expected, but so far I've achieved this with a lot of copy-pasting :)
I'd like to deduplicate my test file by having a common set of such mock.Mock.On(...) calls in my suite.Suite.SetupTest(), and just override them somehow for the specific tests where they need to be slightly different
Am I on the right path here, or have wandered off into weird territory?
What is the recommended way I should be testing something like this?
Is there a recommended way to undo a mock.Mock.On(...) or easily / safely modify mock.Mock.ExpectedCalls?
What if mock.Mock.On(...) replaced any Call in ExpectedCalls that had the same .Method and .Arguments?
Or, what if there was a more explicit mock.Mock.Off(...) that removed such a matching Call from ExpectedCalls?
Would you be interested in a PR for such things?
Firstly, I love this library so much! Hooray! Thanks for sharing! <3
I'm using
suite.Suiteandmock.Mockand I have test suites where a number of tests share almost identical mocks, differing only where test-case-specific calls are mocked to fail (in order to test different failure conditions), e.g.The subject under test hits many functions like this, so I feel it is important for test confidence that I mock them all and assert that they are being called as expected, but so far I've achieved this with a lot of copy-pasting :)
I'd like to deduplicate my test file by having a common set of such
mock.Mock.On(...)calls in mysuite.Suite.SetupTest(), and just override them somehow for the specific tests where they need to be slightly differentAm I on the right path here, or have wandered off into weird territory?
What is the recommended way I should be testing something like this?
Is there a recommended way to undo a
mock.Mock.On(...)or easily / safely modifymock.Mock.ExpectedCalls?What if
mock.Mock.On(...)replaced anyCallinExpectedCallsthat had the same.Methodand.Arguments?Or, what if there was a more explicit
mock.Mock.Off(...)that removed such a matchingCallfromExpectedCalls?Would you be interested in a PR for such things?