Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Integration testing with TestСontainers-Go
Search
Nikolay Kuznetsov
June 18, 2020
Programming
0
130
Integration testing with TestСontainers-Go
GopherCon Europe 2020 - Lightning talk
Nikolay Kuznetsov
June 18, 2020
Tweet
Share
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
Integration testing with TestContainers-Go
nikolayk812
0
260
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
170
TestContainers + JUnit 5 = elegant integration and e2e tests for microservices
nikolayk812
2
350
Integration and end-to-end testing with TestСontainers
nikolayk812
0
120
Integration and end-to-end testing with TestСontainers
nikolayk812
0
29
Other Decks in Programming
See All in Programming
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
810
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.8k
Microservices rules: What good looks like
cer
PRO
0
1.3k
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
380
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
160
俺流レスポンシブコーディング 2025
tak_dcxi
14
8.6k
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
380
【CA.ai #3】ワークフローから見直すAIエージェント — 必要な場面と“選ばない”判断
satoaoaka
0
240
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
1
710
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
11
11k
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
450
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
130
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
55
12k
[SF Ruby Conf 2025] Rails X
palkan
0
510
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Six Lessons from altMBA
skipperchong
29
4.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.7k
Being A Developer After 40
akosma
91
590k
Site-Speed That Sticks
csswizardry
13
1k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
100
YesSQL, Process and Tooling at Scale
rocio
174
15k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Cult of Friendly URLs
andyhume
79
6.7k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
390
Transcript
Integration testing with TestСontainers-Go Nikolay Kuznetsov GopherCon Europe 18 Jun
2020 @nikolayk812
2 unit tests passed, 0 integration tests
Basic integration test
Getting a database for testing • Local database • In-memory
mock • Docker!
Docker advantages • 100% compatible databases • Same version as
production • Empty DB state
Integration testing with Docker
Easy-peasy! docker run -d -p 5432:5432 postgres:12.1
• Host port conflicts • Not ready сontainer / service
• Resource leak (the container keeps running) • Stale data (if reusing the same container) What could go wrong?
Solving some issues
None
Docker API docs.docker.com/engine/api/latest
Exec example
None
TestContainers-Go github.com/testcontainers/testcontainers-go • Docker Go client under the hood •
Host port randomization • Containers clean up at the test shutdown • Readiness waiting strategies
As simple as pgContainer, err := tc.GenericContainer(ctx, tc.GenericContainerRequest{ ContainerRequest: tc.ContainerRequest{
Image: "postgres:12.1", ExposedPorts: []string{"5432/tcp"}, }, })
Host port randomization • API to get a host port:
• Prevents port conflicts • Enables parallel builds port, err := pgContainer.MappedPort(ctx, "5432/tcp")
Containers cleanup: Ryuk github.com/testcontainers/moby-ryuk • Ryuk kills containers (networks, volumes)
by labels • TC assigns labels to started containers • TC keeps a connection to Ryuk open • Ryuk acts when the connection is terminated
Waiting strategies • Host port • HTTP • SQL •
Logs • Custom • Multi
Host port waiting strategy • Impl checks both from outside
and inside container • Default (customizable) timeout is 60 seconds tc.ContainerRequest{ Image: "postgres:12.1", ExposedPorts: []string{"5432/tcp"}, WaitingFor: wait.ForListeningPort("5432/tcp"), },
HTTP waiting strategy WaitingFor: wait.ForHTTP("/health"). WithPort("8080/tcp"). WithStatusCodeMatcher( func(status int) bool
{ return status == http.StatusOK }),
Takeaways • testcontainers.org • Balance between flexibility, speed and features
• Great for integration tests • Possible to use for end-to-end tests
Thank you! @nikolayk812 nikolayk812