-
-
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
Document test exception handling #3730
Comments
Team decision:
|
If no-one has taken this up yet I would like to work on it if that's ok. Although since I have never contributed here a gentle guidance would be helpful. |
Yes, I think we should add an "Other Exceptions" section after "Assertions" and "Assumptions". @driptaroop Feel free to take this on if you're still interested. Sorry for the delay! |
@marcphilipp thanks. I will take it up and assign the issue to myself. PS: couldn't figure out how to assign the issue to myself but I will take it up nonetheless :) |
Documents how exceptions in tests are handled. This PR contains documentation that describes, 1. Uncaught exceptions cause test failures by default 2. How assertions are implemented using exceptions 3. JUnit 5 does not differentiate between failed assertions and other exceptions but IDEs and other tools may choose to do so by checking for instances of AssertionError 4. Adds assertDoesNotThrow example for Java Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
This comment was marked as outdated.
This comment was marked as outdated.
As pointed out in the PR, this commit changes the title of the topic to 'Exception Handling' Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
This PR fixes various comments, 1. added cross ref to "Third-party Assertion Libraries" 2. wrapped lines to 90 char 3. made the anchors hierarchical 4. added note for assertJ's no-exception assertion 5. used static imports for Assertions 6. created separate sections for assertThrows and assertThrowsExactly 7. explicitly mentioned that explicitly mention that a throws clause has no effect. Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
fix lint issues Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
1. added documentation for assertThrows and assertThrowsExactly return type and provided examples. 2. converted all the in code assertion messages to comments 3. fixed a mistake in test Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
The new "Exception Handling" section can now be viewed in the snapshot documentation: https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-exceptions |
It seems there is currently not one single place which describes how exceptions in tests are handled. This can lead to confusion regarding behavior for unexpected exceptions, especially when they are checked exceptions, see for example #3508.
This information is currently split across the documentation, such as the
assertDoesNotThrow
method documentation, which says:JUnit 4 has a separate FAQ entry for this1.
It might therefore be good to have one place (probably a new User Guide section?) where the exception handling is documented:
throws
clause has to be added to the test methodthrows
clause has no effect (e.g. it does not indicate an "expected exception")throws Exception
instead ofthrows CheckedExceptionA, CheckedExceptionB, CheckedExceptionC
since the latter introduces a lot of unnecessary clutter2assertDoesNotThrow
to explicitly indicate unexpected exceptions, but it is not requiredassertThrows
/assertThrowsExactly
But this section should probably be targeted at regular users, so it should not go into detail regarding how extensions can handle exceptions. That seems to already be covered in the User Guide section about extensions.
What do you think?
Deliverables
Footnotes
Though that entry is slightly confusing because it recommends using
throws ...
forIndexOutOfBoundsException
, which is an unchecked exception. ↩It seems not everyone agrees that using
throws Exception
there is fine. But personally I am not sure if developers really deliberately list all checked exceptions, or if most often they just use the IDE action for adding athrows
clause. ↩I am not sure though how strong this separation still exists for JUnit 5. I thought I head read about it in the JUnit 5 documentation before, but I cannot find it right now. And in some cases there seems to be no such differentiation, e.g. assertAll()'s exception-handling behavior turns all test programming errors into test failures #3436. ↩
The text was updated successfully, but these errors were encountered: