As long as you have Docker, every test gets its own throwaway database and Redis, so you can verify integration code before access is granted.

Key takeaways

  • Testcontainers uses Docker to spin up real databases and services for each test run and tears them down afterward; the only prerequisite is Docker.
  • For an FDE, this means you can test integration code before the customer grants staging access.
  • The Go version requires you to set up wait strategies yourself and provides Snapshots so every test starts with a clean database.

In your first week at a customer, the ticket requesting staging access is usually still sitting unprocessed in the infrastructure team's queue. Meanwhile, you already need to write the Postgres read/write layer and the Redis caching layer for the service the customer requested. Your mock tests all pass, but mocks can't tell you whether those SQL statements actually run correctly on a real Postgres.

Testcontainers fills exactly this gap. According to its official website, 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 a Forward Deployed Engineer, this means in practice being freed from a major dependency tied to someone else's schedule. From day one, you can test integration code against a real database on your own laptop.

Is it mature enough to bring into customer projects?

The Java version was created by Richard North in 2015 and released under the MIT license. On December 11, 2023, Docker announced the acquisition of AtomicJar, the company behind Testcontainers. Docker said that Testcontainers' pulls on Docker Hub had doubled over the past year, from 50 million to 100 million, and committed to keeping the open-source components' license unchanged.

That last point matters more to you than the numbers. When you propose adding a library to a customer's codebase, the first question the security or legal team usually asks is about the license. Having a clear answer ready makes that conversation much shorter.

According to the official website, Testcontainers supports multiple languages and testing frameworks, with Docker as the only prerequisite. The Java version is primarily aimed at integration testing of the data access layer, connecting to MySQL, PostgreSQL, or Oracle running in containers. It can also run an entire application together with its dependencies in short-lived test mode.

Imagine an order service written in Go

Suppose the customer is a retail chain and you're writing a Go service that reads orders from Postgres. You have three tests: create a new order, read the order you just created, and delete the order.

If all three tests share one database, the delete test could destroy data the read test needs. The outcome then depends on execution order, and these "sometimes green, sometimes red" failures are the fastest way to destroy a customer's trust in a test suite.

The Go version has a ready-made answer for this: its Postgres module includes a Snapshot feature that lets every test start from a clean database. With each test having its own database, the three tests don't interfere with each other, and results no longer depend on execution order.

Before opening the docs, it helps to walk through the steps of your test suite. Below is pseudocode for clarifying your thinking, not real function names from the library:

// 伪代码:步骤顺序,不是真实 API
1. 启动 Postgres 容器,并显式设置等待策略
2. 准备三个测试所需的 schema 和示例数据
3. 使用 Snapshot,让每个测试都在干净的数据库上运行
4. 运行测试:创建、读取、删除订单
5. 结束运行;容器被删除

When reading the Go Postgres module's page, you only need to find two things: an example using Snapshot to give each test a clean database, and where to declare the wait strategy. Copy those two snippets into your first test, get it running, then write the second one.

What about Redis?

The caching layer comes with one caveat: modules across language versions aren't necessarily equivalent in features. The Redis module mentioned here belongs to the Node.js version, which is a different language version from the Go Postgres module above. If the customer's caching service is written in Node.js, install the module 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 customer will run. State this explicitly in the pull request description, because the customer's code reviewers will definitely ask. If it's a Go service, check the Go documentation first; don't assume an equivalent module exists.

Pitfall number one: "Is the container ready?"

The container finishing startup doesn't mean the Postgres inside is ready to accept connections. The Go Postgres module's documentation states it clearly: there is no default wait strategy; you must set one yourself.

Skip this step, and your test suite may run fine on a powerful laptop but fail randomly on the customer's slower CI machine. Treat the wait strategy as a mandatory part of every container declaration, not an option to add later; and run the test suite on the customer's CI early so problems surface sooner.

What can't it replace?

The most obvious limitation is right there in its selling point: the only requirement is Docker. So during customer requirements discovery, before promising to deliver an integration test suite, first ask whether the customer's dev laptops and CI allow running Docker.

The second limitation is that how closely the containers resemble the customer's environment depends entirely on your configuration. The Postgres version, extensions, and sample data are all your choices. Passing tests on a Postgres version different from production proves less than you might think.

Therefore, Testcontainers lets you start work before staging exists, but it can't replace staging. It catches bugs in SQL, caching, and migrations early; access permissions, data volumes, and real network configurations still need to be verified in the customer's environment.

What to learn first, and how to put it on your resume

A sensible order: first learn enough Docker to read container logs, then write one integration test for the data access layer in the language you use most, and only then add techniques like Redis and Snapshot. Every step should run both on your laptop and on CI.

When reading FDE job postings, look for mentions of deploying to customer environments or working with restricted access; those are places where this skill is worth highlighting in your application materials.

On your resume, don't just list library names; write the results: you completed integration testing with a real database before the customer granted staging access, how many tests you wrote, and how long they take to run.

The staging ticket may sit for another week. The test suite running real Postgres on your laptop doesn't have to wait for anyone.

Was this article helpful?

Thanks for your feedback!

Next on the roadmap · Phase 2: Full-stack engineering capability — Migrations that have already run on the customer's database must never be modified. Flyway, Rails, and Liquibase all record every executed migration; the right approach is always to add a new file, not to edit an old one.