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 fails when assumption fails #1566

Closed
smithkm opened this issue Oct 23, 2018 · 9 comments
Closed

ExpectedException fails when assumption fails #1566

smithkm opened this issue Oct 23, 2018 · 9 comments

Comments

@smithkm
Copy link

smithkm commented Oct 23, 2018

I have tests that Assume.assumeTrue(false) under some circumstances to indicate the test is not relevant. Some of these tests are using an ExpectedException rule to check for other exceptions. Under JUnit 4.11 the test gets ignored as expected, under JUnit 4.12 the rule tries to match the AssumptionViolatedException and fails.

Probably related to the fix for #687

@kcooney
Copy link
Member

kcooney commented Oct 23, 2018

Thanks for reporting this

If you are using 4.12 I strongly recommend replacing usages of ExpectedException with org.junit.Assert.assertThrows.

smithkm added a commit to smithkm/geowebcache that referenced this issue Oct 23, 2018
smithkm added a commit to smithkm/geowebcache that referenced this issue Oct 23, 2018
smithkm added a commit to smithkm/geowebcache that referenced this issue Oct 23, 2018
@smithkm
Copy link
Author

smithkm commented Oct 24, 2018

It doesn't appear that's in 4.12. For now I've made it work with some @Ignores but I may try putting in my own assertThrown until 4.13

@kcooney
Copy link
Member

kcooney commented Oct 24, 2018

Woops, sorry, assertThrows will be added in JUnit 4.13

@kcooney
Copy link
Member

kcooney commented Oct 24, 2018

Looking at the threads (particularly #720) it sounds like we changed this behavior in 4.11, realized that the new behavior was a bad idea, and reverted to the 4.10 behavior in 4.12.

@smithkm How does your test behave in JUnit 4.10?

@kcooney
Copy link
Member

kcooney commented Oct 24, 2018

@smithkm It looks like we have a test case for exactly this use case:

https://github.com/junit-team/junit4/blob/master/src/test/java/org/junit/rules/ExpectedExceptionTest.java#L279

This results in an AssumptionFailure (i.e. the test will be effectively ignored)

If you call ExpectedException.expect() before calling assumeTrue() or assumeFalse() then the test will fail (not be ignored).

@allanhaywood
Copy link

@kcooney @smithkm Is this still an issue?

@kcooney
Copy link
Member

kcooney commented Dec 2, 2021

@allanhaywood based on the JUnit self tests, ExpectedException works as expected when there is an assumption failure.

Unless someone provides a minimal, complete and verifiable example demonstrating it, I think we should close it as not reproducible

@marcphilipp
Copy link
Member

Optimistically closing. I'd reopen it if someone provides a reproducer.

@allanhaywood
Copy link

@kcooney I agree. Thanks for confirming.

@kcooney kcooney closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2023
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

4 participants