-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Correct behavior with Throwables in Assertions.assertAll() #655
Comments
I think I agree with this change. Of course, one has to be careful not to accidentally catch |
The keyword Or change the JUnit 5 snippet to something like: What happens, when you place the |
@sormuras You're certainly right, that's an unfair comparison and I typed it up that way without even thinking about it (I copy/pasted the JUnit 4 example). I think that the equivalent could be done cleanly if we had a static method
This code does indeed result in the same three errors reported by JUnit 4. A much cleaner method would look like (though it will add a failure every time and we really need something that adds the AssertionError if a Throwable is encountered):
Since the negative assertions are pretty consistently
|
I think adding |
I was about to disagree with you, arguing that If you think about the kind of tests we'd build with With this mindset, a real test would look something like this (sorry it's so long):
Also note that I've included a second form:
Thanks for helping me think this through everyone! |
Overview
While working on the ErrorCollector rule examples for issue #343, I have found a situation that I'm having an interesting time translating from JUnit 4 to JUnit 5. In that issue I had stated that the functional behavior of the ErrorCollector rule could be accomplished via the Assertions.assertAll() method. This is not entirely true and the canonical example provided in the JUnit 4 javadocs is one example of where the translation fails.
The JUnit 4 ErrorCollector example (without the class and rule set-up) is as follows:
When this code is executed by JUnit 4, the test output provides three failures - two are the exceptions and the third is the AssertionError.
My attempt at a JUnit 5 equivalent is as follows (again stripped of unneeded code):
When this code is executed, only the first Executable is run. The Exception handling for assertAll() is documented at http://junit.org/junit5/docs/snapshot/api/org/junit/jupiter/api/Assertions.html#assertAll-java.lang.String-java.util.stream.Stream- and states:
but wouldn't it be better to run the remainder of the Executables (potentially all throwing Exceptions if there is a problem with the test harness) as opposed to simply stopping at the first Exception that's not resolvable to AssertionError? It's my opinion that wrapping any Throwable inside the MultipleFailuresError is preferable as it provides the test developer/runner with more information.
The text was updated successfully, but these errors were encountered: