下面列出了怎么用org.junit.internal.runners.statements.InvokeMethod的API类实例代码及写法,或者点击链接到github查看源代码。
/** {@inheritDoc} */
@Override
protected Statement methodInvoker(final FrameworkMethod method, final Object test) {
return new InvokeMethod(method, test) {
@Override
// CHECKSTYLE:CHECK-OFF IllegalThrow // inherited JUnit throw style
public void evaluate() throws Throwable {
// CHECKSTYLE:CHECK-ON IllegalThrow
try {
super.evaluate();
// CHECKSTYLE:CHECK-OFF IllegalCatch // catching in order to act upon but then throwing the exception again
} catch (final Throwable throwable) {
// CHECKSTYLE:CHECK-ON IllegalCatch
testRunRecording.methodInvokeFailure(throwable);
throw throwable;
}
}
};
}
public static void runRule(TestRule rule, Object target, String methodName) {
Class<?> clazz = target.getClass();
Method method = TestUtils.getMethod(clazz, methodName);
Description description = Description.createTestDescription(clazz, method.getName(), method.getDeclaredAnnotations());
try {
InvokeMethod invokeMethod = new InvokeMethod(new FrameworkMethod(method), target);
rule.apply(invokeMethod, description).evaluate();
} catch (Throwable throwable) {
logger.warning(Arrays.toString(throwable.getStackTrace()));
}
}
/**
* Returns a {@link org.junit.runners.model.Statement} that invokes {@code method} on {@code test}
*/
protected Statement methodInvoker(FrameworkMethod method, Object test) {
return new InvokeMethod(method, test);
}