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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nikolay Kuznetsov
November 07, 2019
Technology
380
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TestContainers + JUnit 5 = elegant integration and e2e tests for microservices
Nikolay Kuznetsov
November 07, 2019
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
Integration testing with TestСontainers-Go
nikolayk812
0
140
Integration testing with TestContainers-Go
nikolayk812
0
280
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
180
Integration and end-to-end testing with TestСontainers
nikolayk812
0
130
Integration and end-to-end testing with TestСontainers
nikolayk812
0
37
Other Decks in Technology
See All in Technology
Dylib Hijacking on macOS: Dead or Alive?
patrickwardle
0
110
AWSとAzureのマルチクラウド活用における強い味方___AWS_Kiroを使った二刀流スキル作成.pdf
duelist2020jp
0
110
サービス内で複数のOP・ASを連鎖させる(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
310
ClaudeCodeでセキュリティ監視業務を半自動化_1年の運用でわかったAIに任せる設計の5つのポイント
kintotechdev
3
520
Introduction to Bill One Development Engineer
sansan33
PRO
0
470
internal/testlog で遊ぼう
rokuosan
0
250
IHV like なユースケースへのOpenID Connect 関連仕様の適用事例
optim
0
310
AI・HPC開発を支えるGPU環境の新しい選択肢 液冷GPUシステム「AquSys」の取り組み
gpuunite_official
0
250
dbt と Snowflake と tag
kevinrobot34
1
250
Claude Teamプランの コスト最適化を考える
rfdnxbro
0
730
[ホンマでっか SRE] あなたはなぜ SRE に?
_awache
0
260
AI駆動開発はどこまで来たのか? ファインディの最新実態調査で読み解く現在地 Devin Con Tokyo
akiratom
2
1.4k
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
55
8.3k
Accessibility Awareness
sabderemane
1
180
Facilitating Awesome Meetings
lara
57
7.1k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
500
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
210
Writing Fast Ruby
sferik
630
63k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
260
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
480
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
430
4 Signs Your Business is Dying
shpigford
187
23k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
670
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 ?