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
TestContainers + JUnit 5 = elegant integration...
Search
Nikolay Kuznetsov
November 07, 2019
Technology
2
350
TestContainers + JUnit 5 = elegant integration and e2e tests for microservices
Nikolay Kuznetsov
November 07, 2019
Tweet
Share
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
Integration testing with TestСontainers-Go
nikolayk812
0
130
Integration testing with TestContainers-Go
nikolayk812
0
250
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
170
Integration and end-to-end testing with TestСontainers
nikolayk812
0
110
Integration and end-to-end testing with TestСontainers
nikolayk812
0
25
Other Decks in Technology
See All in Technology
隙間ツール開発のすすめ / PHP Conference Fukuoka 2025
meihei3
0
190
Amazon Q Developer CLIをClaude Codeから使うためのベストプラクティスを考えてみた
dar_kuma_san
0
360
AWS IAM Identity Centerによる権限設定をグラフ構造で可視化+グラフRAGへの挑戦
ykimi
2
420
MCP サーバーの基礎から実践レベルの知識まで
azukiazusa1
25
12k
Gov-JAWS4回_某団体でのAmazon Bedrock活用検証で見えた“使う側”の課題精度よりもリテラシー
takuma818t
0
160
ソフトウェア品質を支える テストとレビュー再考 / 吉澤 智美さん
findy_eventslides
1
740
Design and implementation of "Markdown to Google Slides" / phpconfuk 2025
k1low
1
320
よくわからない人向けの IAM Identity Center とちょっとした落とし穴
kazzpapa3
2
440
AIがコードを書いてくれるなら、新米エンジニアは何をする? / komekaigi2025
nkzn
25
17k
品質保証の取り組みを広げる仕組みづくり〜スキルの移譲と自律を支える実践知〜
tarappo
2
490
3年ぶりの re:Invent 今年の意気込みと前回の振り返り
kazzpapa3
0
140
AIエージェントは「使う」だけじゃなくて「作る」時代! 〜最新フレームワークで楽しく開発入門しよう〜
minorun365
PRO
9
1.4k
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
192
56k
Visualization
eitanlees
150
16k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
10
920
Build The Right Thing And Hit Your Dates
maggiecrowley
38
2.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Designing for humans not robots
tammielis
254
26k
The Cult of Friendly URLs
andyhume
79
6.7k
Side Projects
sachag
455
43k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Building an army of robots
kneath
306
46k
Transcript
TestContainers + JUnit 5 = elegant integration and e2e tests
for microservices Nikolay Kuznetsov @nikolayk812 TESTING UNITED Vienna, 7 November 2019
About me • Go developer at Zalando Helsinki • Java
developer at Infobip, DevExperts • C developer at Samsung, Motorola
My testing experience • Unit, integration and end-to-end automated tests
development • Various organizational structures ◦ Separate QA teams ◦ QA engineers in a dev team ◦ No QA teams/engineers at all
Key points • Targeting automated testing • Examples and demos
in Java: TestContainers-Java, JUnit 5, Spring Boot • Principles are language-agnostic
Why integration testing?
2 unit tests, 0 integration tests
Tests trade-offs
None
Basic integration test
Integration testing evolution • In-memory mocking • Local DBs •
Vagrant • Docker, Docker Compose • Docker API
Docker architecture
How to start a container for test? • Shell scripts
• Maven plugin • Docker Compose • Docker API • MiniKube, Kubernetes
Shell scripts
Maven plugin github.com/fabric8io/docker-maven-plugin
Docker Compose
Docker API
None
TestContainers flavors
TestContainers Java • github.com/testcontainers/testcontainers-java • Wraps docker-java library • Docker
environment autodiscovery • Host port randomization • Containers clean up on JVM shutdown • Readiness waiting strategies
As simple as var redis = new GenericContainer("redis:5.0.5") .withExposedPorts(6379); var
postgres = new PostgreSQLContainer();
Docker environment autodiscovery
Host port randomization • Prevents port conflicts • Enables parallel
CI builds • API to get an actual host port
Containers cleanup github.com/testcontainers/moby-ryuk
Readiness waiting strategies • Host port • HTTP status/body •
Log message • Docker healthcheck • Combination of above • Custom
Demo setup User Service
Demo scenario User Service INSERT INTO SELECT FROM
Demo github.com/nikolayk812/tu-tc-demo
Demo recap • JUnit 5 integration via Extension API ◦
@TestContainers / @Container • TestContainers Modules ◦ 14 databases ◦ Kafka, MockServer, LocalStack, ToxiProxy, etc
JUnit 5 Extensions • Customizable extension points: ◦ Life-cycle phases
◦ Parameter resolution ◦ Conditional execution, etc • Extension logic registered with @ExtendsWith
github.com/nikolayk812/tu-tc-demo Demo-2: setup User Service
Demo-2: scenario User Service POST /users GET /user/<id>
Demo-2: Docker network User Service user-alias: 8083 postgres-alias: 5432 localhost:
32812
Demo 2 github.com/nikolayk812/tu-tc-demo
Demo-2: recap • Docker network and alias
Why end-to-end testing? • Business flows across multiple services •
Regression, when ◦ + new service ◦ - legacy service
Testing/staging deployed cluster Spring Cloud Kubernetes
Testing against a deployed cluster • Deploy a new service
version to the cluster? • Unexpected versions of dependent services • Unexpected database states ◦ Care to clear after the test? • Parallel CI builds?
On-demand cluster for E2E tests + Locally and at CI
machines + Control over dependent services versions - Time to start all containers - Resources: memory and CPU How to do it?
Kubernetes for E2E tests?
Kubernetes for E2E tests - YAGNI TestContainers + Docker network!
E2E test setup User Service Item Service
Takeaways • https://testcontainers.org • Balance between flexibility, speed and features
• Works on Mac, Linux, Windows
QUESTIONS ?