【发布时间】:2020-07-30 07:58:19
【问题描述】:
我尝试编写自己的 JUnit 5 扩展,提供一些关于测试持续时间的简单信息。 我也想打印出重复信息,但是如何在扩展中访问这些信息? 有没有什么简单的方法,而不是反射或者写入并解析数字到显示名称?
简单示例:
@ExtendWith(TimingExtension.class)
public class MyTestClass {
@RepeatedTest(value = 5, name = "{currentRepetition}/{totalRepetitions}")
public void myTest(TestInfo testInfo, RepetitionInfo repInfo) {
// do some work here...
}
}
public class TimingExtension implements AfterTestExecutionCallback {
@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
if(context.getRequiredTestMethod().getDeclaredAnnotation(RepeatedTest.class) != null) {
System.out.println("This was test X of Y"); // how to get currentRepetition and totalRepetitions here?
}
}
}
【问题讨论】:
标签: java junit5 junit5-extension-model