Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
250
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
160
TestContainers + JUnit 5 = elegant integration and e2e tests for microservices
nikolayk812
2
340
Integration and end-to-end testing with TestСontainers
nikolayk812
0
110
Integration and end-to-end testing with TestСontainers
nikolayk812
0
23
Other Decks in Programming
See All in Programming
iOS 26にアップデートすると実機でのHot Reloadができない?
umigishiaoi
0
130
MDN Web Docs に日本語翻訳でコントリビュートしたくなる
ohmori_yusuke
1
130
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
230
Advanced Micro Frontends: Multi Version/ Framework Scenarios @WAD 2025, Berlin
manfredsteyer
PRO
0
340
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
590
TypeScriptでDXを上げろ! Hono編
yusukebe
1
400
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
300
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
640
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
160
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
570
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
20k
코딩 에이전트 체크리스트: Claude Code ver.
nacyot
0
840
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Agile that works and the tools we love
rasmusluckow
329
21k
The Cult of Friendly URLs
andyhume
79
6.5k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
It's Worth the Effort
3n
185
28k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
How to train your dragon (web standard)
notwaldorf
96
6.1k
Building Adaptive Systems
keathley
43
2.7k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
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