DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Discussion on: The Testcontainers’ MongoDB Module and Spring Data MongoDB in Action

Collapse
alevohin profile image
Yuriy

Tried your workaround solution on your PatchProductLoadITTest and ProductControllerITTest by adding:

  • testcontainers.reuse.enable=true to .testcontainers.properties
  • .withReuse(true) to MONGO_DB_CONTAINER
  • MONGO_DB_CONTAINER.getReplicaSetUrl()+"-my-db-N" to both tests (N=1 for PatchProductLoadITTest and N=2 for ProductControllerITTest) But a container is not reused. How can I make it work?
Thread Thread
silaev profile image
silaev Author

Put it simply, my tests stop each MongoDBContainer in @AfterAll methods. I’ve added if (!MONGO_DB_CONTAINER.isShouldBeReused()) statement to stop MongoDBContainer only if we do not use Testcontainers' reusable feature. See this commit for more details. Thanks for you comment.