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

Mockito Unnecessary Stubbings Everywhere in tests #2308

Closed
Sheikah45 opened this issue Jul 11, 2021 · 6 comments
Closed

Mockito Unnecessary Stubbings Everywhere in tests #2308

Sheikah45 opened this issue Jul 11, 2021 · 6 comments
Labels

Comments

@Sheikah45
Copy link
Member

In Junit 5 mockito changed how they detect unnecessary stubbings.

Previously unecessary stubbings were declared when the stubbing was never used during the tests. Now unneccesary stubbings are declared on a test by test basis. So this now throws a bunch of unnecessary stubbing errors for each of our beforeEach methods as not all stubbings in those methods are used every time.

It would be nice to refactor the tests to remove this effect and turn back on strict stubbing guidelines.

@Sheikah45 Sheikah45 added the bug label Jul 11, 2021
@Marc-Spector
Copy link
Collaborator

Are there any advantages to using strict stubbing?

@Sheikah45
Copy link
Member Author

Mainly to make sure that the tests don't become cluttered with unecessary code or setup that could have unintended effects in the future

@Sheikah45
Copy link
Member Author

It isn't crucial but still is something

@Brutus5000
Copy link
Member

In JUnit 5 default, a mock method counts as verify already, so can just run verifyNoMoreInteractions as @AfterEach . I think that's the reason why it's strict by default.
You can disable this for certain mocks (= where it makes sense) by calling lenient().when(...).then...

@Sheikah45
Copy link
Member Author

Yeah it is more so that when we moved to junit 5 if a mock was made in the before each that wasn't actually used in the test then it would throw a strict stubbing error.

This caused a lot of errors as the before is used for general setup in a lot of tests and not every mock is used every test but might be used in a few of them.

This the refactor headache

@Sheikah45
Copy link
Member Author

This was resolved in #3070

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

No branches or pull requests

3 participants