@@ -179,12 +179,11 @@ script, depending on where `@Sql` is declared. If a default cannot be detected,
179
179
180
180
If you need to configure multiple sets of SQL scripts for a given test class or test
181
181
method but with different syntax configuration, different error handling rules, or
182
- different execution phases per set, you can declare multiple instances of `@Sql`. With
183
- Java 8, you can use `@Sql` as a repeatable annotation. Otherwise, you can use the
184
- `@SqlGroup` annotation as an explicit container for declaring multiple instances of
185
- `@Sql`.
182
+ different execution phases per set, you can declare multiple instances of `@Sql`. You can
183
+ either use `@Sql` as a repeatable annotation, or you can use the `@SqlGroup` annotation
184
+ as an explicit container for declaring multiple instances of `@Sql`.
186
185
187
- The following example shows how to use `@Sql` as a repeatable annotation with Java 8 :
186
+ The following example shows how to use `@Sql` as a repeatable annotation:
188
187
189
188
[tabs]
190
189
======
@@ -204,17 +203,21 @@ Kotlin::
204
203
+
205
204
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
206
205
----
207
- // Repeatable annotations with non-SOURCE retention are not yet supported by Kotlin
206
+ @Test
207
+ @Sql("/test-schema.sql", config = SqlConfig(commentPrefix = "`"))
208
+ @Sql("/test-user-data.sql")
209
+ fun userTest() {
210
+ // run code that uses the test schema and test data
211
+ }
208
212
----
209
213
======
210
214
211
215
In the scenario presented in the preceding example, the `test-schema.sql` script uses a
212
216
different syntax for single-line comments.
213
217
214
218
The following example is identical to the preceding example, except that the `@Sql`
215
- declarations are grouped together within `@SqlGroup`. With Java 8 and above, the use of
216
- `@SqlGroup` is optional, but you may need to use `@SqlGroup` for compatibility with
217
- other JVM languages such as Kotlin.
219
+ declarations are grouped together within `@SqlGroup`. The use of `@SqlGroup` is optional,
220
+ but you may need to use `@SqlGroup` for compatibility with other JVM languages.
218
221
219
222
[tabs]
220
223
======
@@ -239,7 +242,8 @@ Kotlin::
239
242
@Test
240
243
@SqlGroup(
241
244
Sql("/test-schema.sql", config = SqlConfig(commentPrefix = "`")),
242
- Sql("/test-user-data.sql"))
245
+ Sql("/test-user-data.sql")
246
+ )
243
247
fun userTest() {
244
248
// Run code that uses the test schema and test data
245
249
}
@@ -249,10 +253,10 @@ Kotlin::
249
253
[[testcontext-executing-sql-declaratively-script-execution-phases]]
250
254
=== Script Execution Phases
251
255
252
- By default, SQL scripts are run before the corresponding test method. However, if
253
- you need to run a particular set of scripts after the test method (for example, to clean
254
- up database state), you can use the `executionPhase` attribute in `@Sql`, as the
255
- following example shows:
256
+ By default, SQL scripts are run before the corresponding test method. However, if you
257
+ need to run a particular set of scripts after the test method (for example, to clean up
258
+ database state), you can set the `executionPhase` attribute in `@Sql` to
259
+ `AFTER_TEST_METHOD`, as the following example shows:
256
260
257
261
[tabs]
258
262
======
@@ -281,20 +285,19 @@ Kotlin::
281
285
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
282
286
----
283
287
@Test
284
- @SqlGroup(
285
- Sql("create-test-data.sql",
286
- config = SqlConfig(transactionMode = ISOLATED)),
287
- Sql("delete-test-data.sql",
288
- config = SqlConfig(transactionMode = ISOLATED),
289
- executionPhase = AFTER_TEST_METHOD))
288
+ @Sql("create-test-data.sql",
289
+ config = SqlConfig(transactionMode = ISOLATED))
290
+ @Sql("delete-test-data.sql",
291
+ config = SqlConfig(transactionMode = ISOLATED),
292
+ executionPhase = AFTER_TEST_METHOD)
290
293
fun userTest() {
291
294
// run code that needs the test data to be committed
292
295
// to the database outside of the test's transaction
293
296
}
294
297
----
295
298
======
296
299
297
- Note that `ISOLATED` and `AFTER_TEST_METHOD` are statically imported from
300
+ NOTE: `ISOLATED` and `AFTER_TEST_METHOD` are statically imported from
298
301
`Sql.TransactionMode` and `Sql.ExecutionPhase`, respectively.
299
302
300
303
[[testcontext-executing-sql-declaratively-script-configuration]]
0 commit comments