@java.lang.annotation.Inherited @java.lang.annotation.Retention(value: RetentionPolicy.RUNTIME) @java.lang.annotation.Target(value: [ElementType.TYPE, ElementType.METHOD]) @org.spockframework.runtime.extension.ExtensionAnnotation(value: TestcontainersExtension) @interface Testcontainers
@Testcontainers is a Spock extension to activate automatic
startup and stop of containers used in a test case.
The Testcontainers extension finds all fields that extend org.testcontainers.containers.GenericContainer or org.testcontainers.containers.DockerComposeContainer and calls their container lifecycle methods. Containers annotated with spock.lang.Shared will be shared between test methods. They will be started only once before any test method is executed and stopped after the last test method has executed. Containers without spock.lang.Shared annotation will be started and stopped for every test method.
The annotation @Testcontainers can be used on a superclass in
the test hierarchy as well. All subclasses will automatically inherit
support for the extension.
Example:
@Testcontainers
class MyTestcontainersTests extends Specification {
// will be started only once in setupSpec() and stopped after last test method
@Shared
MySQLContainer MY_SQL_CONTAINER = new MySQLContainer()
// will be started before and stopped after each test method
PostgreSQLContainer postgresqlContainer = new PostgreSQLContainer()
.withDatabaseName('foo')
.withUsername('foo')
.withPassword('secret')
def 'test'() {
expect:
MY_SQL_CONTAINER.running
postgresqlContainer.running
}
}
| Type Params | Return Type | Name and description |
|---|---|---|
|
abstract boolean |
disabledWithoutDocker()Whether tests should be disabled (rather than failing) when Docker is not available. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |