-
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
ExpectedException doesn't fail when an AssertionError is expected but not thrown #583
ExpectedException doesn't fail when an AssertionError is expected but not thrown #583
Conversation
When a user expected the production code to throw an AssertionError by using ExpectedException (together with the #handleAssertionErrors option) but the code under test didn't do so the test was not failing. This was because the ExpectedException rule caught its own AssertionError issued to signal that the expected exception was not thrown.
@@ -72,6 +72,9 @@ | |||
hasSingleAssumptionFailure()}, | |||
{ThrowExpectedAssertionError.class, everyTestRunSuccessful()}, | |||
{ | |||
DontThrowAssertionErrorButExpectOne.class, | |||
hasSingleFailureWithMessage("Expected test to throw an instance of java.lang.AssertionError")}, |
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.
The above two lines should be indented by one additional tab.
Thanks, good catch! I've added two formatting-related comments inline. Unfortunately, formatter settings are still not under source control (waiting for #426). |
I fixed the formatting. Just let me know in case I missed something. |
…ertion-error-expected-but-not-thown ExpectedException doesn't fail when an AssertionError is expected but not thrown
Thanks! Can you make a note in the release notes? https://github.com/KentBeck/junit/wiki/4.12-release-notes |
@dsaff I added a polished version of the description of the issue to the release notes. I didn't know whether it should go under a bugfixes section so I just listed it like the release notes for the other pull requests. I hope that was okay. |
@UrsMetz, perfectly fine. We're still experimenting with that wiki, so there's not necessarily a "right" and "wrong" answer here. |
Thank you @UrsMetz for fixing this bug. I just encountered it while writing a test. |
now,I lost in this bug. |
When a tests expects code under test to throw an AssertionError by using ExpectedException (together with the #handleAssertionErrors option) but the code doesn't do so the test is not failing. This is because the ExpectedException rule catches its own AssertionError issued to signal that the expected exception is not thrown.
The attached commits fix this.