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
Detect unnecessary stubbings #558
Comments
Thanks @Raibaz for opening this issue. |
It would be great to have a default value of 'detectUnnecessaryStubbing' set to true, so to avoid setting it everywhere. |
In the end, this is basically about having [verification confirmation] executed by default. Perhaps it may be just about having the MockkExtension implement AfterEachCallback (see here) and call |
Turns out this is actually a duplicate of #334. |
@Raibaz so, is there already a solution to this issue? Thanks! |
Not yet, but as it turns out implementing it is likely going to be a bit easier than I thought :) |
Great, I'm willing to test a version of MockK with this new behaviour as soon as is available! |
Implemented in 1.12.4. |
Mockito throws an exception when a function is stubbed and then not actually invoked.
This is particularly useful when doing TDD, or generally when writing tests first, because it allows to stub a function, have the test fail because it was not invoked, and then make it pass by implementing the invocation.
We could add a parameter to the
mockk()
function and the@MockK
annotation, or a configuration flag to make it global, so that it works somewhat like this:A potential issue I see in this is the case when there are two tests executing
service.anotherFunction()
, one stubbing and invokingcollaborator.function()
and one not stubbing nor invoking it.We need to find a way to detect that it's ok for the second test not to invoke
collaborator.function()
even if it was stubbed in another test.The text was updated successfully, but these errors were encountered: