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
Improved IDE experience for JUnit5 - visual comparison failure #1667
Improved IDE experience for JUnit5 - visual comparison failure #1667
Conversation
Removes the need to check for JUnit each time createArgumentsAreDifferentException() is called and also makes it easy to 1. extend and 2. streamline further if source 1.8 compatibility is introduced.
Codecov Report
@@ Coverage Diff @@
## release/2.x #1667 +/- ##
=================================================
- Coverage 87.36% 87.34% -0.02%
Complexity 2442 2442
=================================================
Files 301 302 +1
Lines 6293 6307 +14
Branches 787 788 +1
=================================================
+ Hits 5498 5509 +11
- Misses 600 603 +3
Partials 195 195
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any instructions on how I can test this PR to verify the difference in IDE behavior?
a388254
to
d2ab570
Compare
This implementation is not perfect. Under Eclipse, if you're using the JUnit 4 but happen to have OpenTest on the classpath, then you'll use the visual diff capability again. This is because the JUnit 4 runner in Eclipse doesn't try and catch/handle The only way around that would be for |
Why do you call this behavior imperfect? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thank you!!!
Can you do 2 more checks for us?
- does it work with IDEA, too?
- can you build the project and inspect all pom files (they should be somewhere under "build" dirs) and ensure that we don't ship the new dependency?
src/main/java/org/mockito/exceptions/verification/junit/package-info.java
Outdated
Show resolved
Hide resolved
src/test/java/org/mockito/internal/verification/VerificationOverTimeImplTest.java
Show resolved
Hide resolved
Sorry, it was a typo. It should have read "... then you'll lose the visual diff capability again." Perfect behaviour, in my mind, would be that it determined which runner was actually running (as opposed to merely being on the classpath), and throw the exception that was appropriate for that runner. But I think this is an edge case that probably isn't worth the extra complexity. Not perfect, but good enough. |
This will be difficult for me to do, as I don't have IDEA installed. But I can't see why it wouldn't work
Will do. I did note that I need to make sure that an optional Import-Package is added to the MANIFEST.MF too. |
Grab it from JetBrains site, IDEA community/open source edition is free and easy to install |
Got it! Thank you for confirming. Yes, the ideal behavior is that we get clean visual diff for all IDEs. Let's move on. It seems that having OpenTest4J + JUnit4 on classpath is an edge case. Also, I would hope that Eclipse will catch up and start handling OpenTest4J exceptions. @TimvdLippe, this is an interesting argument for our discussion about adding hard dependency on OpenTest4J. If we add such dependency today, then Eclipse + JUnit4 + Mockito (with OpenTest4J) combo loses visual diff feature (unless we write code to detect the runner - a fragile complexity better avoided). Just an FYI. I don't mind to restart the discussion. Thanks guys!!! |
I am absolutely fine with not adding the hard-dependency 😄 |
👍
Just to clarify (in case it wasn't clear): The problem is not merely having both OpenTest4J and JUnit4 on the class path. JUnit 5 and OpenTest4J have been deliberately designed so that they can happily co-exist with JUnit 4 on the same classpath. The problem (in Eclipse at least) is if you mix the JUnit 4 runner with OpenTest4J exceptions (which this current PR will do if you have OpenTest4J on the classpath) - the visual diff will not work, because Eclipse's implementation of the JUnit 4 runner special-cases the JUnit 3 & 4
Actually, the issue of losing the visual diff doesn't have anything to do with whether the dependency on OpenTest4J is hard or soft. It has more to do with how the decision is made about which exception to throw. The above problem would still occur even if we made the dependency on OpenTest4J a hard one, unless we did the same stack trace trick (ie, check which runner invoked us and throw the appropriate exception).
Welcome! Honoured to be able to meaningfully contribute to such a popular project! |
d2ab570
to
42f802e
Compare
Could you maybe add a new subproject which has some sample tests with instructions on how to inspect the diff? That would ease future development so that we can check if regressed on that. Thanks for all the hard work, good progress! |
I did this - I can confirm that opentest4j does not appear as a dependency in any of the generated pom files. I also added the manifest change: |
I'll sleep on it, but to be honest my initial thoughts are that I feel this is overreaching a little. I think the Mockito tests should focus on the fact that it throws Perhaps this could be the subject of a separate issue/PR which I can get to if I find time, or else someone else can take it on. |
I suggest we move on. We won't be able to automatically test how IDEs integrate with xUnit runners. Manual tests will be forgotten. We never had tests for this feature and it did not regress. Eventual regression will not be a blocker. If we encounter one, then we can prioritize a solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ready merge. @TimvdLippe, OK?
I didn't count it as a blocker, more as a future improvement. I am okay with merging as-is. |
When JUnit5+Mockito is used in modern IDE (IDEA, Eclipse) we now show "visual" comparison failure pop-up for certain Mockito exceptions (such as ArgumentsAreDifferent).
Fixes #1663.