-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question / feature-suggestion: built-in way to overwrite / clear ExpectedCalls? #558
Comments
I would ideally create a new mock for that particular test, which means the struct/interface which embeds the mock would be new. you could also write subtests for that particular case by grouping it. You could do |
FWIW I would also love a mock.Mock.ClearExpectedMethod... when executing unit tests where there is some setup and then many corner cases to be tested, the ability to clear anything with a particular methodname would be super helpful. Personally, I would be happy if this were a blunt call (i.e. anything with mock.ClearExpectedMethod("Foo"). |
why did this get closed out? especially considering the opened PR hasn't been approved or merged? |
you can use call func (c *Call) Times(i int) *Call when you call on again , will return last call arguments example
|
@stephenjayakar , I had a look at it now. Not sure why the original author closed the PR. I've added a comment asking if they'd be happy to re-open and just change the name of the function from |
Any progress on this? |
I usually use the following to reset the expected calls, but it would indeed be nice to have this exposed as part of the API of the mock object. mock.ExpectedCalls = mock.ExpectedCalls[:0] |
Any progress? I see this as a nice feature. |
Same here, use case is to have a tool to deal with setting correct expected parameters when order is not deterministic (due to map iteration for example). I set all possible variations of the call and then I would like to be able to reset everything. |
This issue has been solved by this PR with the introduction of the |
Firstly, I love this library so much! Hooray! Thanks for sharing! <3
I'm using
suite.Suite
andmock.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.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 anyCall
inExpectedCalls
that had the same.Method
and.Arguments
?Or, what if there was a more explicit
mock.Mock.Off(...)
that removed such a matchingCall
fromExpectedCalls
?Would you be interested in a PR for such things?
The text was updated successfully, but these errors were encountered: