Back to Testcontainers Java

Spock

docs/test_framework_integration/spock.md

2.0.51.4 KB
Original Source

Spock

Spock extension for Testcontainers library, which allows to use Docker containers inside of Spock tests.

Usage

@Testcontainers class-annotation

Specifying the @Testcontainers annotation will instruct Spock to start and stop all testcontainers accordingly. This annotation can be mixed with Spock's @Shared annotation to indicate, that containers shouldn't be restarted between tests.

<!--codeinclude-->

PostgresContainerIT inside_block:PostgresContainerIT

<!--/codeinclude-->

Adding Testcontainers Spock support to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

=== "Gradle" groovy testImplementation "org.testcontainers:testcontainers-spock:{{latest_version}}" === "Maven" xml <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers-spock</artifactId> <version>{{latest_version}}</version> <scope>test</scope> </dependency>

Attributions

The initial version of this project was heavily inspired by the excellent JUnit5 docker extension by FaustXVI.