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
"description" not printing when verify args don't match #1712
Comments
Not pretty but this seems to work if I use a
now prints out
|
I would like to analyze this issue and eventually provide fixes. |
I can also verify the same issue. |
Seems like a bug. Please submit a PR. Thanks! |
The cause of this is that Reporter.argumentsAreDifferent() can return
according to whether opentest or junit is available in the classpath. Neither of these, crucially, extends MockitoAssertionError. Hence the exception is not caught in Description.verify and wrapped in a MockitoAssertionError with the description. That would only happen if neither opentest nor junit were in the classpath. I think the catch block there should also catch these other exceptions and handle them in a similar way to include the description text. |
It's extending those because of tooling and IDE support, I believe. In IntelliJ IDEA for example, this error is displayed really nice. You can see and compare the differences on the arguments. |
The various ArgumentsAreDifferent exceptions come from org.mockito.internal.junit.ExceptionFactory, which deals solely with that condition. The header comment of MockitoAssertionError suggests it should be the base of all verification errors triggered by verify() methods. So maybe some refactoring is required. I don't know enough to say whether the solution is to handle the exceptions which are actually being thrown or change to throw subclasses of MockitoAssertionError which would then fix the issue. |
Created a PR with a possible solution: #1949 |
Mockito version 2.27.0
I have a test that uses
description
inside averify
method. Thedescription
is correctly printing when the test fails because we don't interact with the mockResults in this failure message:
In this case the test failed because there were no interactions with this mock. However if we update the SUT so that it calls the method with the wrong argument:
The test still fails. But this time it does not include the description:
The text was updated successfully, but these errors were encountered: