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

Testing: make "failBecauseExpectedAssertionErrorWasNotThrown()" in test throw something else than AssertionError... #318

Closed
fge opened this issue Jan 2, 2015 · 1 comment

Comments

@fge
Copy link
Contributor

fge commented Jan 2, 2015

(and find a shorter name for it?)

The problem is that writing tests is rather unnatural compared to, for instance, the core API's "failBecauseExc..." Argh, can't say it. shouldHaveThrown().

Since it throws an AssertionError, if we write, in a test:

try {
    myAssertionHereWhichFails();
    failBecauseExpectedAssertionErrorWasNotThrown();
} catch (AssertionError e) {
    someVerifyCode();
}

even though the naturally expected result that the verification code was not hit, it is.

Instead one has to write this rather unwieldy code:

try {
    myAssertionHereWhichFails();
    return;
} catch (AssertionError e) {
    someVerifyCode();
    return;
}
failBecauseExpectedAssertionErrorWasNotThrown();

Why not make it throw a custom AssertionErrorExpectedException instead?

Also, why not an alternate name of wasExpectingAssertionError()?

@fge
Copy link
Contributor Author

fge commented Jan 2, 2015

Submitted a patch on my topic/jsr203 branch which does exactly what I suggested. Comments?

joel-costigliola pushed a commit that referenced this issue Jan 27, 2015
Eat own dog's food:

* create a new AssertionErrorExpectedException;
* add a .wasExpectingAssertionError() method to TestFailures.
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

No branches or pull requests

1 participant