Skip to content

Commit 4059d04

Browse files
Add JavaDoc to Spock's Testcontainers annotation (#6802)
Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
1 parent f9dabb6 commit 4059d04

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

modules/spock/src/main/groovy/org/testcontainers/spock/Testcontainers.groovy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ import java.lang.annotation.Retention
88
import java.lang.annotation.RetentionPolicy
99
import java.lang.annotation.Target
1010

11+
/**
12+
* {@code @Testcontainers} is a Spock extension to activate automatic
13+
* startup and stop of containers used in a test case.
14+
*
15+
* <p>The Testcontainers extension finds all fields that extend
16+
* {@link org.testcontainers.containers.GenericContainer} or
17+
* {@link org.testcontainers.containers.DockerComposeContainer} and calls their
18+
* container lifecycle methods. Containers annotated with {@link spock.lang.Shared}
19+
* will be shared between test methods. They will be
20+
* started only once before any test method is executed and stopped after the
21+
* last test method has executed. Containers without {@link spock.lang.Shared}
22+
* annotation will be started and stopped for every test method.</p>
23+
*
24+
* <p>The annotation {@code @Testcontainers} can be used on a superclass in
25+
* the test hierarchy as well. All subclasses will automatically inherit
26+
* support for the extension.</p>
27+
*
28+
* <p>Example:</p>
29+
*
30+
* <pre>
31+
* &#64;Testcontainers
32+
* class MyTestcontainersTests extends Specification {
33+
*
34+
* // will be started only once in setupSpec() and stopped after last test method
35+
* &#64;Shared
36+
* MySQLContainer MY_SQL_CONTAINER = new MySQLContainer()
37+
*
38+
* // will be started before and stopped after each test method
39+
* PostgreSQLContainer postgresqlContainer = new PostgreSQLContainer()
40+
* .withDatabaseName('foo')
41+
* .withUsername('foo')
42+
* .withPassword('secret')
43+
*
44+
* def 'test'() {
45+
* expect:
46+
* MY_SQL_CONTAINER.running
47+
* postgresqlContainer.running
48+
* }
49+
* }
50+
* </pre>
51+
*/
1152
@Inherited
1253
@Retention(RetentionPolicy.RUNTIME)
1354
@Target([ElementType.TYPE, ElementType.METHOD])

0 commit comments

Comments
 (0)