Skip to content

Commit bd92a31

Browse files
committed
Add information about lifecycle of testcontainers to documentation
Signed-off-by: Vanio Begic <[email protected]>
1 parent d16630f commit bd92a31

File tree

1 file changed

+22
-0
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing

1 file changed

+22
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ All that is needed to do that is adding javadoc:org.springframework.boot.testcon
4747

4848
include-code::importcontainers/MyConfiguration[]
4949

50+
== Lifecycle of managed containers
51+
52+
If you have used the annotations and extensions provided by Testcontainers framework, then the lifecycle of container instances is managed by the Testcontainers framework.
53+
Please refer to the official documentation for the information about lifecycle of the containers, when managed by the Testcontainers framework.
54+
55+
When the containers are managed by Spring as beans, then the lifecycle is clearly defined by Spring.
56+
The container beans are created and started before the beans of other types are created.
57+
This process ensures that any beans, which rely on functionality provided by the containers, can use those functionalities.
58+
59+
The test containers can be started multiple times.
60+
Like any other beans the test containers are created and started once per application context managed by the TestContext Framework.
61+
For details about how TestContext framework manages the underlying application contexts and beans therein, please refer to the official Spring documentation.
62+
63+
The container beans are stopped after the destruction of beans of other types.
64+
This ensures that any beans depending on the functionalities provided by the containers are cleaned up first.
65+
66+
The containers are stopped as part of the application shutdown process, managed by the TestContext framework.
67+
When the application context gets shutdown, the containers are shutdown as well.
68+
This usually happens after all tests using that specific cached application context have finished executing, but may happen earlier depending on the caching behavior configured in TestContext Framework.
69+
70+
It is important to note that a single test container instance can be, and often is, retained across execution of tests from multiple test classes.
71+
5072
[[testing.testcontainers.service-connections]]
5173
== Service Connections
5274

0 commit comments

Comments
 (0)