Skip to content

Instantly share code, notes, and snippets.

@RainerW
Created June 26, 2012 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RainerW/2998970 to your computer and use it in GitHub Desktop.
Save RainerW/2998970 to your computer and use it in GitHub Desktop.
JUnit #25 Idea
package com.example.junit25;
import org.junit.Ignore;
import org.junit.internal.AssumptionViolatedException;
import org.junit.internal.runners.model.EachTestNotifier;
import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
public class JUnit4AssumtionRunner extends BlockJUnit4ClassRunner{
public JUnit4AssumtionRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
// just a copy because of JUnit's final policy
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
Description description= describeChild(method);
if (method.getAnnotation(Ignore.class) != null) {
notifier.fireTestIgnored(description);
} else {
runLeafPatched(methodBlock(method), description, notifier);
}
}
/**
* Runs a {@link Statement} that represents a leaf (aka atomic) test.
*/
protected final void runLeafPatched(Statement statement, Description description,
RunNotifier notifier) {
EachTestNotifier eachNotifier= new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
try {
statement.evaluate();
} catch (AssumptionViolatedException e) {
// Actual patch:
notifier.fireTestIgnored(description);
// eachNotifier.addFailedAssumption(e);
} catch (Throwable e) {
eachNotifier.addFailure(e);
} finally {
eachNotifier.fireTestFinished();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment