【发布时间】:2021-12-22 10:37:31
【问题描述】:
目前我正在进行集成测试,并且这个控制器涵盖了许多表,因此使用 @BeforeEach 插入事务数据,我想使用 sql 脚本,我尝试过这样..
@Sql(scripts = {"classpath:/business-test-data.sql"})
public class IntegrationTest extend AbstractIT {
@BeforeEach
void init() {
// method from AbstractIT
// Clear DB, Redis, Kafka, etc
}
@Test
void someTest(){}
.. 原来 Spring 在清除 DB 之前执行了 business-test-data.sql。
那么,清除数据库后如何执行business-test-data.sql?任何建议或其他方法将不胜感激。谢谢。
注意事项:
- 对于模式和主数据,它们已经与嵌入式 postgres 初始化一起执行,我想避免使用此脚本插入事务数据。
- Clear DB 是继承自 AbstractIT 类的方法,更改清除表的方式看起来也会影响其他集成测试,所以我也想避免它。
【问题讨论】:
标签: spring spring-boot integration-testing