【发布时间】:2019-12-27 22:26:33
【问题描述】:
我正在使用 org.springframework.boot.test.context.SpringBootTest 运行 Spring Boot 集成测试。
我编写了一个 JUnit 4 org.junit.rules.TestRule,我将它用作 org.junit.ClassRule。
看起来像这样:
public class MyRule implements TestRule {
public Statement apply(final Statement statement, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
// do something
try {
statement.evaluate();
} finally {
// clean up
}
}
};
}
}
不幸的是, // 清理代码在 Spring Boot 上下文关闭之前执行。
在 Spring 应用程序关闭后,我必须将代码放在哪里才能执行它?
【问题讨论】:
-
@RomanVottner 据我所知,它们将在应用程序关闭之前执行。
标签: java spring spring-boot junit junit4