No staging access yet? Testcontainers gives you a real Postgres
With nothing but Docker, every test run gets its own throwaway database and Redis, so integration code can be checked before anyone grants you access.
In brief
- Testcontainers creates real databases and services in Docker for each test run and removes them afterwards; Docker is the only requirement.
- For FDEs, it makes it possible to test integration code before the client grants access to staging.
- The Go version requires you to set your own wait strategy and offers Snapshot so each test gets a clean database.
In your first week at a client, the ticket asking for staging access is usually still sitting untouched in the infrastructure team’s queue. Meanwhile you have already had to write the Postgres read/write layer and the Redis cache layer for the service they need. The mocks pass, but mocks cannot tell you whether your SQL actually runs correctly on a real Postgres.
Testcontainers fills exactly that gap. According to its official site, it is an open-source library that provides lightweight, throwaway instances of databases and anything else that can run in a Docker container. You declare your test’s dependencies in code, run the tests, and the containers are created and then removed.
For an FDE, the practical meaning is that you shed a major dependency on someone else’s schedule. Integration code can be tested against a real database on your laptop from day one.
Is it mature enough to bring to a client?
The Java version was created in 2015 by Richard North and is released under the MIT licence. On 11 December 2023 Docker announced it was acquiring AtomicJar, the company behind Testcontainers. Docker said pulls on Docker Hub had doubled over the previous year, from 50 million to 100 million, and committed to keeping the licences of the open-source components unchanged.
That last detail matters more to you than the numbers. When you propose adding a library to a client’s repository, the first question from security or legal is usually the licence. Having a clear answer ready shortens that conversation.
The official site says Testcontainers supports many languages and testing frameworks, and requires only Docker. The Java version targets integration tests for the data access layer against MySQL, PostgreSQL or Oracle running in containers. It can also run the whole application in a short-lived test mode alongside its dependencies.
Picture an order service written in Go
Suppose the client is a retail chain and you are writing a Go service that reads orders from Postgres. You have three tests: create a new order, read back the order just created, and delete an order.
If all three tests share one database, the delete test can wreck data the read test needs. Execution order then decides the outcome, and that kind of “sometimes green, sometimes red” failure destroys a client’s trust in a test suite faster than anything.
The Go version has a ready answer: its Postgres module includes a Snapshot feature so that each test starts with a clean database. When each test has its own database, the three tests are independent and results no longer depend on the order they run in.
Before opening the docs, it helps to sketch the order of steps for the suite. The block below is pseudocode for orientation, not the library’s real function names:
// Pseudocode: the order of steps, not the real API
1. Start a Postgres container with an explicit wait strategy
2. Prepare the schema and sample data the three tests need
3. Use Snapshot so each test works on a clean database
4. Run the tests: create, read, delete an order
5. End the run; the container is removed
When you read the Go Postgres module page, look for exactly two things: the example that uses Snapshot to give each test a clean database, and where the wait strategy is declared. Copy those two snippets into your first test, get it green, and only then write the second.
What about Redis?
The cache layer comes with one caveat: modules do not necessarily offer the same features in every language. The Redis module mentioned here belongs to the Node.js version, a different language edition from the Go Postgres module above. If the client’s cache service is written in Node.js, the module is installed as a dev dependency:
npm install @testcontainers/redis --save-dev
Installing it as a dev dependency means the library belongs to the test suite, not to the code the client will run. Say so explicitly in the pull request description, because that is the question the client’s reviewer will ask. For a Go service, check the Go documentation before assuming an equivalent module exists.
The first trap is “is the container ready yet?”
A container that has finished starting does not mean the Postgres inside it is accepting connections. The documentation for the Go Postgres module states plainly that there is no default wait strategy; you have to set one yourself.
Skip this step and your suite may run fine on a powerful laptop but fail at random on the client’s slower CI machines. Treat the wait strategy as a mandatory part of every container declaration, not an option to add later, and run the suite on the client’s CI early to surface the problem.
What can it not replace?
The clearest limit sits in the pitch itself: the only thing you need is Docker. So in customer discovery, ask whether the client’s developer laptops and CI are allowed to run Docker before you promise an integration test suite.
The second limit is that a container resembles the client’s environment only as far as you configure it. The Postgres version, extensions and sample data are all choices you make. A green test on a different Postgres version from production proves less than you think.
Testcontainers therefore lets you get ahead of staging, but it does not replace staging. It catches SQL, cache and migration bugs early. Access permissions, data volumes and real network configuration still have to be checked in the client’s environment.
What to learn first, and how to tell it on your CV
A sensible order: learn enough Docker to read container logs, then write an integration test for the data access layer in the language you use most, and only then add Redis and techniques such as Snapshot. Each step should run both on your laptop and in CI.
When reading FDE job ads, look for passages about deploying into client environments or working while access is still restricted; that is where this skill deserves a mention in your application.
On your CV, do not just list the library’s name. Describe the result: you tested integration against a real database before the client granted staging access, with how many tests and how long they took to run.
The staging ticket may sit untouched for another week. A test suite running on a real Postgres on your laptop does not have to wait for anyone.
Was this article useful?
Thanks for the feedback!