相关文章推荐
逼格高的西瓜  ·  测试 Databricks JDBC ...·  2 月前    · 
苦恼的地瓜  ·  Three.js ...·  1 年前    · 
伤情的消防车  ·  Win11 Dev Build ...·  1 年前    · 
卖萌的水桶  ·  第二节 曲艺·  1 年前    · 
宽容的佛珠  ·  波斯建筑_百度百科·  2 年前    · 

Warning

Reusable Containers is still an experimental feature and the behavior can change. Those containers won't stop after all tests are finished.

The Reusable feature keeps the containers running and next executions with the same container configuration will reuse it. To use it, start the container manually by calling start() method, do not call stop() method directly or indirectly via try-with-resources or JUnit integration , and enable it manually through an opt-in mechanism per environment. To reuse a container, the container configuration must be the same .

Reusable containers are not suited for CI usage and as an experimental feature not all Testcontainers features are fully working (e.g., resource cleanup or networking).

How to use it

  • Enable Reusable Containers
    • through environment variable TESTCONTAINERS_REUSE_ENABLE=true
    • through user property file ~/.testcontainers.properties , by adding testcontainers.reuse.enable=true
    • not through classpath properties file see this comment
    • Define a container and subscribe to reuse the container using withReuse(true)
    • GenericContainer container = new GenericContainer("redis:6-alpine")
          .withExposedPorts(6379)
          .withReuse(true)
      
    • Start the container manually by using container.start()
    • Reusable Container with Testcontainers JDBC URL

      If using the Testcontainers JDBC URL support the URL must follow the pattern of jdbc:tc:mysql:8.0.36:///databasename?TC_REUSABLE=true. TC_REUSABLE=true is set as a parameter of the JDBC URL.

  •