Skip to content
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

Conversation

UrsMetz
Copy link
Contributor

@UrsMetz UrsMetz commented Dec 23, 2012

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.

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")},
Copy link
Member

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.

@marcphilipp
Copy link
Member

Thanks, good catch! I've added two formatting-related comments inline. Unfortunately, formatter settings are still not under source control (waiting for #426).

@UrsMetz
Copy link
Contributor Author

UrsMetz commented Dec 28, 2012

I fixed the formatting. Just let me know in case I missed something.

@marcphilipp
Copy link
Member

@UrsMetz Thanks!

@dsaff Looks ready to be merged to me. Can you please take a look?

dsaff pushed a commit that referenced this pull request Jan 3, 2013
…ertion-error-expected-but-not-thown

ExpectedException doesn't fail when an AssertionError is expected but not thrown
@dsaff dsaff merged commit ad0f505 into junit-team:master Jan 3, 2013
@dsaff
Copy link
Member

dsaff commented Jan 3, 2013

Thanks! Can you make a note in the release notes?

https://github.com/KentBeck/junit/wiki/4.12-release-notes

@UrsMetz
Copy link
Contributor Author

UrsMetz commented Jan 4, 2013

@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.

@dsaff
Copy link
Member

dsaff commented Jan 7, 2013

@UrsMetz, perfectly fine. We're still experimenting with that wiki, so there's not necessarily a "right" and "wrong" answer here.

@stefanbirkner
Copy link
Contributor

Thank you @UrsMetz for fixing this bug. I just encountered it while writing a test.

@qrfcoding
Copy link

now,I lost in this bug.

@UrsMetz UrsMetz deleted the expected-exception-fail-when-assertion-error-expected-but-not-thown branch September 10, 2015 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants