@SqlMergeMode

@SqlMergeMode 用于注解测试类或测试方法,以配置方法级 @Sql 声明是否与类级 @Sql 声明合并。如果未在测试类或测试方法上声明 @SqlMergeMode,则默认情况下将使用 OVERRIDE 合并模式。使用 OVERRIDE 模式,方法级 @Sql 声明将有效覆盖类级 @Sql 声明。

@SqlMergeMode is used to annotate a test class or test method to configure whether method-level @Sql declarations are merged with class-level @Sql declarations. If @SqlMergeMode is not declared on a test class or test method, the OVERRIDE merge mode will be used by default. With the OVERRIDE mode, method-level @Sql declarations will effectively override class-level @Sql declarations.

注意,方法级 @SqlMergeMode 声明会覆盖类级声明。

Note that a method-level @SqlMergeMode declaration overrides a class-level declaration.

以下示例演示如何在类级别使用 @SqlMergeMode

The following example shows how to use @SqlMergeMode at the class level.

Java
@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 Set the @Sql merge mode to MERGE for all test methods in the class.
Kotlin
@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
	}
}
2 Set the @Sql merge mode to MERGE for all test methods in the class.

以下示例演示如何在方法级别使用 @SqlMergeMode

The following example shows how to use @SqlMergeMode at the method level.

Java
@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 Set the @Sql merge mode to MERGE for a specific test method.
Kotlin
@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
	}
}
2 Set the @Sql merge mode to MERGE for a specific test method.