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

@SqlMergeMode

@SqlMergeMode 用于标注测试类或测试方法,以配置方法级别的 @Sql 声明是否与类级别的 @Sql 声明合并。 若未在测试类或测试方法上声明 @SqlMergeMode,则默认使用 OVERRIDE 合并模式。 在 OVERRIDE 模式下,方法级别的 @Sql 声明将有效地覆盖类级别的 @Sql 声明。spring-doc.cadn.net.cn

请注意,方法级的@SqlMergeMode声明会覆盖类级声明。spring-doc.cadn.net.cn

以下示例展示如何在类级别使用@SqlMergeModespring-doc.cadn.net.cn

@SpringJUnitConfig(TestConfig.class)
@Sql("/test-schema.sql")
@SqlMergeMode(MERGE) (1)
class UserTests {

	@Test
	@Sql("/user-test-data-001.sql")
	void standardUserProfile() {
		// run code that relies on test data set 001
	}
}
1 为类中的所有测试方法设置 @Sql 合并模式为 MERGE
@SpringJUnitConfig(TestConfig::class)
@Sql("/test-schema.sql")
@SqlMergeMode(MERGE) (1)
class UserTests {

	@Test
	@Sql("/user-test-data-001.sql")
	fun standardUserProfile() {
		// run code that relies on test data set 001
	}
}
1 为类中的所有测试方法设置 @Sql 合并模式为 MERGE

以下示例展示了如何在方法级别使用@SqlMergeModespring-doc.cadn.net.cn

@SpringJUnitConfig(TestConfig.class)
@Sql("/test-schema.sql")
class UserTests {

	@Test
	@Sql("/user-test-data-001.sql")
	@SqlMergeMode(MERGE) (1)
	void standardUserProfile() {
		// run code that relies on test data set 001
	}
}
1 为特定测试方法将@Sql事务合并模式设置为MERGE
@SpringJUnitConfig(TestConfig::class)
@Sql("/test-schema.sql")
class UserTests {

	@Test
	@Sql("/user-test-data-001.sql")
	@SqlMergeMode(MERGE) (1)
	fun standardUserProfile() {
		// run code that relies on test data set 001
	}
}
1 为特定测试方法将@Sql事务合并模式设置为MERGE