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
Comments
Are there any advantages to using strict stubbing? |
Mainly to make sure that the tests don't become cluttered with unecessary code or setup that could have unintended effects in the future |
It isn't crucial but still is something |
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. |
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 |
This was resolved in #3070 |
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.
The text was updated successfully, but these errors were encountered: