对于最新稳定版本,请使用 Spring Framework 7.0.6spring-doc.cadn.net.cn

@Sql

@Sql 用于在测试类或测试方法上添加注解,以配置在集成测试期间针对指定数据库执行的 SQL 脚本。以下示例展示了如何使用它:spring-doc.cadn.net.cn

@Test
@Sql({"/test-schema.sql", "/test-user-data.sql"}) (1)
void userTest() {
	// run code that relies on the test schema and test data
}
1 为此测试运行两个脚本。
@Test
@Sql("/test-schema.sql", "/test-user-data.sql") (1)
fun userTest() {
	// run code that relies on the test schema and test data
}
1 为此测试运行两个脚本。