下面列出了怎么用org.junit.internal.runners.model.EachTestNotifier的API类实例代码及写法,或者点击链接到github查看源代码。
private void invokeTest(RunNotifier notifier, TestExecutorType type, FrameworkMethod method) {
if ((type == null) || TestExecutorType.LOCAL.equals(type)) {
runLeaf(methodBlock(method), describeChild(method), notifier);
} else {
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, describeChild(method));
try {
eachNotifier.fireTestStarted();
execute(type, method.getMethod()).get();
} catch (Throwable e) {
log.error("Test " + method + " failed with exception ", e);
eachNotifier.addFailure(unwrap(e));
} finally {
eachNotifier.fireTestFinished();
}
}
}
@Override
public void runChild(final FrameworkMethod method, final RunNotifier notifier) {
final Description description = describeChild(method);
if (this.isIgnored(method)) {
notifier.fireTestIgnored(description);
} else {
final EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
boolean ignored = false;
try {
this.methodBlock(method).evaluate();
} catch (AssumptionViolatedException ave) {
eachNotifier.addFailedAssumption(ave);
} catch (Throwable e) {
if (validateForGraphComputer(e)) {
eachNotifier.fireTestIgnored();
logger.info(e.getMessage());
ignored = true;
} else
eachNotifier.addFailure(e);
} finally {
if (!ignored)
eachNotifier.fireTestFinished();
}
}
}
private void endTracing(FrameworkMethod method, RunNotifier notifier) {
if (shouldCreateNewTraceObject(method)) {
TraceContext traceContext = getTraceContext();
try {
Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
// Trace is already detached from the ThreadLocal storage.
// Happens when root trace method is tested without @IsRootSpan.
EachTestNotifier testMethodNotifier = new EachTestNotifier(notifier, super.describeChild(method));
String traceObjectAlreadyDetachedMessage = "Trace object already detached. If you're testing a trace root, please add @IsRootSpan to the test method";
testMethodNotifier.addFailure(new IllegalStateException(traceObjectAlreadyDetachedMessage));
} else {
trace.close();
}
} finally {
traceContext.removeTraceObject();
}
}
}
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
if (method.getAnnotation(Ignore.class) != null) {
notifier.fireTestIgnored(description);
} else {
setLogContext(method);
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
try {
runTestMethod(method, eachNotifier, config.getTimeoutRetries());
} finally {
eachNotifier.fireTestFinished();
clearLogContext();
}
}
}
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
if (method.getAnnotation(Ignore.class) != null) {
notifier.fireTestIgnored(description);
} else {
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
try {
runTestMethod(method, eachNotifier);
} finally {
eachNotifier.fireTestFinished();
}
}
}
@Override
public void run(final RunNotifier notifier) {
EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
Statement statement = classBlock(notifier);
try {
statement.evaluate();
} catch (AssumptionViolatedException ave) {
testNotifier.fireTestIgnored();
} catch (StoppedByUserException sbue) {
throw sbue;
} catch (Throwable t) {
LOG.warning("Retry class: " + getDescription().getDisplayName());
retry(testNotifier, statement, t, getDescription());
}
}
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
if (method.getAnnotation(Ignore.class) != null) {
notifier.fireTestIgnored(description);
} else {
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
try {
runTestMethod(method, eachNotifier);
} finally {
eachNotifier.fireTestFinished();
}
}
}
protected EachTestNotifier makeNotifier(FrameworkMethod method,
RunNotifier notifier) {
Description description= describeChild(method);
return new EachTestNotifier(notifier, description);
}
protected EachTestNotifier makeNotifier(FrameworkMethod method,
RunNotifier notifier) {
Description description= describeChild(method);
return new EachTestNotifier(notifier, description);
}
/**
* <code>springMakeNotifier()</code> is an exact copy of
* {@link BlockJUnit4ClassRunner BlockJUnit4ClassRunner's}
* <code>makeNotifier()</code> method, but we have decided to prefix it with
* "spring" and keep it <code>private</code> in order to avoid the
* compatibility clashes that were introduced in JUnit between versions 4.5,
* 4.6, and 4.7.
*/
private EachTestNotifier springMakeNotifier(FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
return new EachTestNotifier(notifier, description);
}
/**
* Creates a notifier for each test.
*
* @param method
* the {@link FrameworkMethod}, must not be {@code null}
* @param notifier
* the {@link RunNotifier}, must not be {@code null}
* @return an instance of {@link EachTestNotifier}, never {@code null}
*/
private EachTestNotifier createNotifier(final FrameworkMethod method, final RunNotifier notifier) {
return new EachTestNotifier(notifier, describeChild(method));
}