Description
I am using a subclass of RunListener to listen and respond to JUnit events. I'm having an issue handling assumptionFailures in @BeforeClass annotated methods...
In other scopes (@test or @before methods) assumptionFailures seem to correctly call EachTestNotifier's addFailedAssumption() and in time fireTestAssumptionFailed methods as I would expect. This is from the ParentRunner class:
protected final void runLeaf(Statement statement, Description description,
RunNotifier notifier) {
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
try {
statement.evaluate();
} catch (AssumptionViolatedException e) {
eachNotifier.addFailedAssumption(e);
} catch (Throwable e) {
eachNotifier.addFailure(e);
} finally {
eachNotifier.fireTestFinished();
}
}
When an AssumptionViolatedException is caught, listeners are notified of this.
However, when an assumption failure is raised in a @BeforeClass annotated method instead we get a call to fireTestIgnored as can be seen here:
public void run(final RunNotifier notifier) {
EachTestNotifier testNotifier = new EachTestNotifier(notifier,
getDescription());
try {
Statement statement = classBlock(notifier);
statement.evaluate();
} catch (AssumptionViolatedException e) {
testNotifier.fireTestIgnored();
} catch (StoppedByUserException e) {
throw e;
} catch (Throwable e) {
testNotifier.addFailure(e);
}
}
Now an assumption failure looks the same as an ignored test although there is no corresponding @ignore attribute to glean any information from.
Why is an assumption failure being turned into an ignored test only in this case? Is there a reason it can't be treated as a normal assumptionFailure? Since there is still logic being used to determine the validity of the assumption, this isn't the same as a straight up @ignored test.