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

Add global setting to set default strictness in test runners #2532

Open
Mordavolt opened this issue Jan 4, 2022 · 4 comments
Open

Add global setting to set default strictness in test runners #2532

Mordavolt opened this issue Jan 4, 2022 · 4 comments

Comments

@Mordavolt
Copy link

Hey folks,

According to the docs, Mockito should have switched to strict mocks by default since v4. I've been eagerly waiting for this release, but it seems the feature is not there.

Furthermore, following the conversations here #2460, #1769 and #1517 I conclude that this is not something that is going to happen?

To clarify, I would like to do something like mockito.strict = true and expect the whole project to be evaluated as such (the default value can stay false). There is no easy way to enable strict mocks across the entire project.

Would it be possible to get an official statement on the plans regarding this feature?

@TimvdLippe
Copy link
Contributor

Good question! The intention was to switch the default in Mockito 4, but after user feedback, we decided to postpone that decision. That said, I do think we should have an optional global switch that turns on strictness.

For that, the behavior should be as follows:

  1. If you don't set mockito.strict, the default behavior of the runner should be lenient. When users explicitly use the strict runner for a test case, it should be strict for that test case only.
  2. If you set mockito.strict, the default behavior of the runner should be strict. When users explicitly use the lenient runner for a test case, it should be lenient for that test case only.

This also hopefully allows us to get easier user feedback on this feature, as more projects can turn this feature on and get more information on its behavior.

@TimvdLippe TimvdLippe changed the title STRICT_STUBS by default Add global setting to set default strictness in test runners Jan 6, 2022
@TimvdLippe
Copy link
Contributor

In fact. Rather than making it a boolean, we probably want to mirror the values to be those of https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/quality/Strictness.html E.g. mockito.defaultStrictness = STRICT_STUBS or mockito.defaultStrictness = WARN. That should allow us to extend the enum in the future if we need to, without locking ourselves into only 2 options.

@grimreaper
Copy link
Contributor

ref #1924 for tons of discussion as well

@TWiStErRob
Copy link
Contributor

Is this ready for dev? I would love to see it implemented, having to write it in every test or introduce a base class / custom rule seems like an overkill, especially that there are such easy (and global) ways to pick other config like mockmaker.

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

No branches or pull requests

4 participants