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
260
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
170
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 Technology
See All in Technology
AWS Lambda durable functions を使って AWS Lambda の15分の壁を超えてみよう
matsuzawatakeshi
0
110
複雑さを受け入れるか、拒むか? - 事業成長とともに育ったモノリスを前に私が考えたこと #RSGT2026
murabayashi
0
250
_第4回__AIxIoTビジネス共創ラボ紹介資料_20251203.pdf
iotcomjpadmin
0
160
2025年 山梨の技術コミュニティを振り返る
yuukis
0
130
アプリにAIを正しく組み込むための アーキテクチャ── 国産LLMの現実と実践
kohju
1
270
20251222_サンフランシスコサバイバル術
ponponmikankan
2
150
Autonomous Database - Dedicated 技術詳細 / adb-d_technical_detail_jp
oracle4engineer
PRO
5
12k
モダンデータスタックの理想と現実の間で~1.3億人Vポイントデータ基盤の現在地とこれから~
taromatsui_cccmkhd
2
290
[PR] はじめてのデジタルアイデンティティという本を書きました
ritou
0
560
AWSの新機能をフル活用した「re:Inventエージェント」開発秘話
minorun365
2
520
人工知能のための哲学塾 ニューロフィロソフィ篇 第零夜 「ニューロフィロソフィとは何か?」
miyayou
0
210
ルネサンス開発者を育てる 1on1支援AIエージェント
yusukeshimizu
0
130
Featured
See All Featured
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
51k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
210
sira's awesome portfolio website redesign presentation
elsirapls
0
98
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
150
How to build a perfect <img>
jonoalderson
0
4.8k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
420
A better future with KSS
kneath
240
18k
RailsConf 2023
tenderlove
30
1.3k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
WCS-LA-2024
lcolladotor
0
400
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
0
320
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
590
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 ?