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
AssertionError in MockUtil.getMockHandlerOrNull
in our regression test suite
#2823
Comments
@TimvdLippe I think I do have time to look at it, feel free to assign it to me, thank you. |
…t suite. Fixes mockito#2823 Signed-off-by: Andriy Redko <drreta@gmail.com>
@TimvdLippe It seems like issue was caused by one test case, |
Fixes #2823 Signed-off-by: Andriy Redko <drreta@gmail.com>
Hey! We hit this error as well, after upgrading to Mockito 5.3.1 from 3.x (using Java 17) This happened unreproducibly as well because the failing tests are different from the ones using a non-standard mockmaker. If this can't be fixed (because it's not reproducible), please improve the documentation and/or the assertion with a better error message like "Please do not use different MockMakers for the same target class(?)" or something. I would send a PR myself but I'm not sure myself what's going on there. It's also very disconcerting that doing a thing in one test class affects other test classes in when using mockito. Can't this be avoided (I'm writing this knowing I have no clue about Mockito internals)? |
Thanks @mr1chter
Could you share a bit more details - in you tests you also change the default mock maker from test class to test class? Could you share minimal examples how do you use different mock makers in your tests?
This particular fix was specific to Mockito but we could certainly improve the documentation / error reporting, just need to understand the context a bit more. |
We don't change the MockMaker from the default in almost all cases. There was a single one where I had to change it to the subclass MockMaker because a specific interface could not be mocked[1]. When I did this, some tests left and right of it failed due to the AssertionError, but inconsistently. When running all failing and changed tests in isolation (using gradle test --test Mytest) nothing failed anymore. But running some of them at once leads to AssertionErrors, which was very strange(looks like a race condition or something). I just dropped in with the debugger and it said that in this specific assertion it gets a
As you might see, this is happening in a Regarding documentation, I might open another issue because there are still quite some places that say "subclass mockMaker is the default" or "in the future, inline will be the default" even though this changed. [1] The interface that could not be mocked(lets call it A) is also weird because it is not special in any way. The mocking fails with a "classic" InternalError: class redefinition failed, invalid class. I followed until this error with the debugger and noticed that it tried to redefine 4 interfaces (three of which are superinterfaces of A) and managed to identify an even more simple interface which can't be mocked. But somehow, A can be successfully mocked with the inline mockmaker in other test classes. |
I got the inline MockMaker to work, sidestepping the problem (because now, no subclass mockmaker is used anywhere). So my takeaway is now to advise people to use one mockmaker or another, but not both, as long as those are used within the same Java process anywhere. |
Sorry for the wall of text monologue, next time I'll open a proper ticket. |
Not a problem, thank you for sharing that
That sounds about right, the order tests are scheduled on forked JVMs introduces randomness, and certainly, just running a test in isolation works all the time.
Please do, thank you
:+1
Yes, similar approach we took for Mockito (to eliminate the possibility of race and isolate tests for differrent mock makers).
Correct, or have some sort of test support for cleaning up the mock maker per test suite (the example that comes into mind is |
We appear to be hitting the following assertion in our test suites:
mockito/src/main/java/org/mockito/internal/util/MockUtil.java
Line 160 in e2e6289
Example error from the logs:
The assertion was introduced in #2701
The text was updated successfully, but these errors were encountered: