I'm looking to improve my integration testing process for Java projects by incorporating Docker. Specifically, I want to know how others are handling external services like Postgres and Redis during testing. Are you using Testcontainers, running shell scripts with 'docker run', or relying on external infrastructure? Also, I've been curious about the challenges you might face such as container startup times, cleanup issues, port collisions, or flakiness in CI environments. I'd really appreciate hearing about what has worked or failed for you. Thanks!
2 Answers
In our projects, we mainly use Testcontainers because it works great with Spring. Just set it up, and it handles spinning up the necessary containers for your tests. This cuts down a lot of hassle! But do keep an eye on your container startup times—some niche containers can be slow, so I make sure to enable reusable containers in tests to speed things up.
Testcontainers have really become the go-to. They handle container cleanup and port management automatically by using random ports, which is super helpful. But there's a downside: our CI tasks run on a VM instead of in containers, leading to slow startup times for the agents. We're currently exploring ways to address that, maybe by reusing agents or considering alternatives like cloud-based testing.
That's interesting! We actually let GitHub Actions manage our service containers, so we don't face those CI startup issues. It makes for a smoother pipeline.”}]},{
Yeah, that's the way to go. Just ensure Docker is enabled on your machine; it simplifies everything.