@ -95,13 +95,22 @@ In addition to the aforementioned mechanisms for running SQL scripts programmati
you can declaratively configure SQL scripts in the Spring TestContext Framework.
you can declaratively configure SQL scripts in the Spring TestContext Framework.
Specifically, you can declare the `@Sql` annotation on a test class or test method to
Specifically, you can declare the `@Sql` annotation on a test class or test method to
configure individual SQL statements or the resource paths to SQL scripts that should be
configure individual SQL statements or the resource paths to SQL scripts that should be
run against a given database before or after an integration test method. Support for
run against a given database before or after an integration test class or test method.
`@Sql` is provided by the `SqlScriptsTestExecutionListener`, which is enabled by default.
Support for `@Sql` is provided by the `SqlScriptsTestExecutionListener`, which is enabled
by default.
NOTE: Method-level `@Sql` declarations override class-level declarations by default. As
of Spring Framework 5.2, however, this behavior may be configured per test class or per
[NOTE]
test method via `@SqlMergeMode`. See
====
xref:testing/testcontext-framework/executing-sql.adoc#testcontext-executing-sql-declaratively-script-merging[Merging and Overriding Configuration with `@SqlMergeMode`] for further details.
Method-level `@Sql` declarations override class-level declarations by default, but this
behavior may be configured per test class or per test method via `@SqlMergeMode`. See
xref:testing/testcontext-framework/executing-sql.adoc#testcontext-executing-sql-declaratively-script-merging[Merging and Overriding Configuration with `@SqlMergeMode`]
for further details.
However, this does not apply to class-level declarations configured for the
`BEFORE_TEST_CLASS` or `AFTER_TEST_CLASS` execution phases. Such declarations cannot be
overridden, and the corresponding scripts and statements will be executed once per class
in addition to any method-level scripts and statements.