-
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
Tests expecting AssumptionViolatedException should be marked as passed, not skipped #1291
Changes from 5 commits
c71c878
939ade5
6def963
e6aee89
4a79e75
ca669b6
aa582cb
95800b6
0ea179f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.junit.internal.runners.statements; | ||
|
||
import org.junit.Test; | ||
import org.junit.internal.AssumptionViolatedException; | ||
import org.junit.runners.model.Statement; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ExpectExceptionTest { | ||
|
||
@Test | ||
public void givenWeAreExpectingAssumptionViolatedExceptionAndAStatementThrowingAssumptionViolatedException() { | ||
ExpectException sut = new ExpectException(new StatementThrowingAssumptionViolatedException(), AssumptionViolatedException.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we instead test this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I'll do that. But I also would like to keep this unit test, which is really a unit test, small. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, having both kinds of tests is fine. The integration test is necessary to verify the bug is fixed; the unit test verifies the contract of the If we keep this test class, please have the class Javadoc say where the integration tests are (using A few suggested changes:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, if you are adding unit tests, please add a test that makes sure that tests that expect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done
Done, but I gave it a more meaningful name, although a bit longer:
Done but I would suggest to consider adopting it.
I find it a great name as it clearly stands out among the many variables (the DOCs, following Meszaros's terminology) which may be defined in a unit test. It also makes it extremely easy to distinguish the "when" step: it's the one (and only, in theory) of the form
Done. I've also added a couple more scenarios:
|
||
|
||
try { | ||
sut.evaluate(); | ||
// then no exception should be thrown | ||
} catch (Throwable e) { | ||
fail("should not throw anything, but was thrown: " + e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Edit: Woops! I see why you need to do an explicit catch; without your fix this test would not fail because of the assumption failure exception being thrown. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ya right! Tricky uh? :) Testing JUnit with JUnit is tricky itself |
||
} | ||
} | ||
|
||
private static class StatementThrowingAssumptionViolatedException extends Statement { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
throw new AssumptionViolatedException("expected"); | ||
} | ||
} | ||
} |
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.
I like descriptive method names but this is a bit long. How about:
whenExpectingAssumptionViolatedExceptionStatementsThrowingItShouldPass
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.
agreed