testcontainers / testcontainers-scala

Docker containers for testing in scala

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to share the same single container instance between suites?

pgorin opened this issue · comments

Hi, first of all, thank you for your work, I use it extensively :)
I wll be glad if you can guide me with this issue!

Regards,
Pato.

Hi @pgorin. At the current moment, there is no supported way for doing this. It's because scalatest doesn't provide any functionality for sharing data like this between tests.

But there is a bit hacky way for sharing containers: you can start containers and just don't stop them. Testcontainers will eventually close all started containers after your tests. There is a special Ryuk container for that. Testcontainers always start it before any other container to avoid resource leaking.

Hi Yuriy, thank you for your reply.
What do you mean about a special Ryuk container? Can I still using TestContainerForAll approach or I have to perform custom before and after routines?

Again, thank you!

https://hub.docker.com/r/testcontainers/ryuk

Can I still using TestContainerForAll approach or I have to perform custom before and after routines?

No, you can't use TestContainerForAll or any other built-in traits for that approach. You will need to manually start containers and don't stop them after tests. Also, you will need to somehow share containers between tests (through some global state).