Skip to content
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

Clarified strict mocks doc #2105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mipo256
Copy link

@mipo256 mipo256 commented Feb 14, 2025

In reality, Mockito is really using stricts mocks by default since 4 major release. So I think it is worth updating this doc :)

@Vampire
Copy link
Member

Vampire commented Feb 14, 2025

Do you have evidence it actually is the default?
You say it is the default since 4 major releases.
The current major release is v5.
But what you linked to says since v4 and also just that it is intended to
What you linked to is just a "planned to be the default for v4 though.

And for example https://github.com/mockito/mockito/blob/main/mockito-core/src/main/java/org/mockito/MockSettings.java#L373 says the default is lenient.
For https://github.com/mockito/mockito/blob/main/mockito-core/src/main/java/org/mockito/junit/MockitoJUnit.java#L34 it seems the default is warn, so behavioral still lenient.
Didn't look further.

@mipo256
Copy link
Author

mipo256 commented Feb 17, 2025

It seems that you're right, I'm sorry. But at least, Mockito has planned to migrate to strict mocks for a very long time, initially it was planned to Mockito v3.

So I think it is at least it does not make much sense to say that Spock like Mockito relies on lenient mocks. Becuase Mockito does not recommend that.

@Vampire
Copy link
Member

Vampire commented Feb 17, 2025

Well, having a look at their docs I'd say even if it were enabled by default, it is not the strictness we talk about here.

As far as I understood those docs, even with using Mockito strict mode you still need to use verifyNoMoreInteractions to achieve the strictness we are talking about here.

It is "a bit stricter" by failing if you do stub a method and it gets called but with different arguments it fails and if you do stub a method and it is not called it fails. But that's imho merely a "mistyped" protection or "refactored" protection but not the strictness mentioned here where any call on the mock would fail. 🤷‍♂️

@Vampire
Copy link
Member

Vampire commented Feb 17, 2025

@leonard84 what do you think?

@Vampire
Copy link
Member

Vampire commented Feb 17, 2025

Unfortunately the term "strict" is used very differently. EasyMock for example also has a strict mode, that there means that also invocation order is checked.

@leonard84
Copy link
Member

Calling Mockito's verifyNoMoreInteractions is basically the same as adding 0 * _ to a Spec.

I agree with @Vampire that "strictness" is not well-defined. We can remove the Like Mockito intro, but saying that Mockito is strict by default would be wrong, they just recommend it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants