下面列出了org.junit.jupiter.api.extension.ExtensionContext#publishReportEntry() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void processFixture(final String type,
final Invocation<Void> invocation,
final ReflectiveInvocationContext<Method> invocationContext,
final ExtensionContext extensionContext) throws Throwable {
final String uuid = UUID.randomUUID().toString();
try {
extensionContext.publishReportEntry(buildStartEvent(
type,
uuid,
invocationContext.getExecutable()
));
invocation.proceed();
extensionContext.publishReportEntry(buildStopEvent(
type,
uuid
));
} catch (Throwable throwable) {
extensionContext.publishReportEntry(buildFailureEvent(
type,
uuid,
throwable
));
throw throwable;
}
}
@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
long start = getStore(context).get("START", long.class);
long duration = System.currentTimeMillis() - start;
// System.out.println("Test method " + context.getRequiredTestMethod().getName() + " took " + duration + " ms");
context.publishReportEntry("exucution time", "" + duration);
}
private static void report(String unit, ExtensionContext context, long elapsedTime) {
String message = String.format("%s '%s' took %d ms.", unit, context.getDisplayName(), elapsedTime);
context.publishReportEntry("Benchmark", message);
}
private static void report(ExtensionContext context, long elapsedTime) {
String message = String.format("Test '%s' took %d ms.", context.getDisplayName(), elapsedTime);
context.publishReportEntry("Benchmark", message);
}