-
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
Add Mock#Reset()
#384
Add Mock#Reset()
#384
Conversation
Provide a methods for clearing all programed expectations from a mock; useful during a TestSuite tear-down method to ensure you have a clean slate between test-runs.
b56518f
to
1d4edf8
Compare
Should all |
@jonnyreeves could you provide an example on how you would use it? I would like to understand the use case better :) |
I'll hop in with my use case. I start a router with a passed in DB, and potentially some others. I'd like to reset the db mock between tests without needing to stop and start the server. So pretty much any case where something can be resource or time intensive to start and stop, that you want to test with a mock. |
@jimmiebtlr you can already do that as follows: // mock
type myMock struct {
mock.Mock
}
// initialise
m := &myMock{}
// [...]
// Reset
m.Mock = mock.Mock{} Have you ever used this? |
Oh, sweet, didn't realize you could do that. |
I have another use case. Here's a component:
Of course I want to test it. I have test suit with one test per feature for the |
@ernesto-jimenez I also think abstracting the resetting of mocks can improve readability, and also standardize the ways of doing that. It is also more aligned with the intuition when using the mocks, as suggested in @Monnoroch example. Using the suite package, it would be nicer to read and easier to understand
Instead of other possibilities such as
or
|
May I suggest a simpler solution that would require a simple modification?
|
Provide a methods for clearing all programed expectations from a mock; useful during a TestSuite tear-down method to ensure you have a clean slate between test-runs.