Reuse Test Containers

· 111 words · 1 minute read

I found every-time I’m developing test cases, lot of time wasted in waiting for test container to come up because once execution completes containers are stopped and removed. So how can we build container once, re-use it thereafter. As per the documentation test container provides an option to prevent deletion of container - reusable-container quickstart

vi ~/.testcontainers.properties
testcontainers.reuse.enable=true

GenericContainer container = new GenericContainer("redis:6-alpine") .withExposedPorts(6379) .withReuse(true)

After making the changes, containers are stopped and not removed. This saves a little bit of time. I was actually searching for an option to keep them running and reuse till I manually stop them. No luck so far! Btw I don’t like their new desktop.