@groovy.util.logging.Slf4j @groovy.transform.CompileStatic class DatabaseCleanupExtension extends java.lang.Object implements IGlobalExtension
Spock global extension that detects the DatabaseCleanup annotation on test classes and methods, and registers the DatabaseCleanupInterceptor to perform database cleanup after annotated tests.
This extension requires a Spring application context provided by the SpringBootTest infrastructure
The extension uses the java.util.ServiceLoader mechanism to discover all available DatabaseCleaner implementations at startup. It validates that each implementation declares a unique databaseType; if duplicates are found, an error is thrown immediately.
At runtime, when cleanup is triggered for a datasource, the framework verifies that a matching cleaner exists for that datasource's database type. If no matching cleaner is found, an error is raised.
By default, validation of misplaced @DatabaseCleanup annotations on non-feature
methods (e.g., setup(), cleanup()) is disabled for performance reasons.
Set the system property grails.testing.cleanup.validate=true to opt into this check:
-Dgrails.testing.cleanup.validate=true
| Type | Name and description |
|---|---|
static java.lang.String |
VALIDATE_PROPERTYSystem property that enables validation of @DatabaseCleanup placement on
non-feature methods. |
| Constructor and description |
|---|
DatabaseCleanupExtension() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
static boolean |
isValidateEnabled()Returns true if the grails.testing.cleanup.validate system property
is set to "true". |
|
void |
start() |
|
void |
visitSpec(SpecInfo spec) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
System property that enables validation of @DatabaseCleanup placement on
non-feature methods. Set to "true" to enable:
-Dgrails.testing.cleanup.validate=true
Returns true if the grails.testing.cleanup.validate system property
is set to "true".