-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Undocumented change to ExpectedException in JUnit 4.11 changes default behavior when expected class is AssertionError. #687
Comments
This change has been introduced in #323. |
It seems there was some controversy about the default behaviour for assertion errors: @dsaff @stefanbirkner Do you remember the details? |
Reading back to #323 and #121, it seems the originally stated problem was that ExpectedException was wrapping thrown Assertion and Assumption violations, so that the original exception was masked. However, in the examples I can find there, in no case was ExpectedException told to expect an AssertionError or AssumptionViolationException. This comment by @dsaff comes closest to describing the current issue: "It's troubling that this test would fail: @test public void throwExpectedAssertionError() { The implementation fixes one problem, but introduces another. |
Ugh. Agreed that this is a bug. Sorry. Could be low-hanging fruit for a contributor with free time. We should block 4.12 on a fix. |
Fixes junit-team#687. junit-team#121 is still fixed. (Pull request junit-team#323 was too rigid.)
Fixes junit-team#687. junit-team#121 is still fixed. (Pull request junit-team#323 was too rigid.)
Fixes junit-team#687. junit-team#121 is still fixed. (Pull request junit-team#323 was too rigid.)
Fixes junit-team#687. junit-team#121 is still fixed. (Pull request junit-team#323 was too rigid.)
about handling assumes and asserts in conjunction with the ExpectedException rule.
about handling assumes and asserts in conjunction with the ExpectedException rule.
Still fixes junit-team#121, but the original fix was superfluous. Added documentation about handling assumes and asserts in conjunction with the ExpectedException rule.
Still fixes junit-team#121, but the original fix was superfluous. Added documentation about handling assumes and asserts in conjunction with the ExpectedException rule.
Still fixes junit-team#121, but the original fix was superfluous. Added documentation about handling assumes and asserts in conjunction with the ExpectedException rule.
Still fixes junit-team#121, but the original fix was superfluous. Added documentation about handling assumes and asserts in conjunction with the ExpectedException rule.
Still fixes junit-team#121, but the original fix was superfluous. Added documentation about handling assumes and asserts in conjunction with the ExpectedException rule.
Extend ExpectedException's documentation and fix #687.
Still fixes junit-team#121, but the original fix was superfluous. Added documentation about handling assumes and asserts in conjunction with the ExpectedException rule.
Prior to JUnit 4.11, a test like this passes:
@rule
public ExpectedException thrown = ExpectedException.none();
@test
public void test() {
thrown.expect(AssertionError.class);
assertTrue(false);
}
With JUnit 4.11, tests like this suddenly fail with the thrown AssertionError, instead of being intercepted and verified by ExpectedException.
On inspecting the code, we see that the behavior of ExpectedException was changed to conditionally include AssertionErrors as a valid Throwable,and that the default behavior was changed from prior versions to ignore AssertionError. The flag handleAssertionErrors defaults to false; a call to the new handleAssertionErrors() method is needed to force it to true. This call is required even whenAssertionError is explicitly expected in the call to expect().
We have test frameworks that throw AssertionErrors, and unit tests for those frameworks that verify that the expected AssertIionErrors are thrown. All those tests fail with JUnit 4.11, unless the tests are changed to force handleAssertionErrors=true.
The text was updated successfully, but these errors were encountered: