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
370
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
36
Other Decks in Technology
See All in Technology
從開發到部署全都交給 AI:實作 AI 驅動的自動化流程
appleboy
0
170
GitHub Copilot app最速の発信の裏側
tomokusaba
1
260
元・セキュリティ学習経験0大学生による業務紹介 / An Introduction to the Job by a Former College Student with Zero Security Training Experience
nttcom
0
380
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
210
MySQL & MySQL HeatWave Report - June 2026
freshdaz
0
170
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
200
#エンジニアBooks 30分でわかる 「技術記事を書く技術」 / engineer-books 2026-06-30
jnchito
1
100
現場のトークンマネジメント
dak2
1
190
千葉での単身赴任からAWSをやり続け、千葉に戻ってきた話
yama3133
1
120
螺旋型キャリアの生存戦略 / kinoko-conf2026
rakus_dev
1
1k
「勝手に広まる」人気 AI エージェントを爆速で作ろう!(AWS Summit Japan 2026講演資料)
minorun365
PRO
10
2.6k
Oracle Cloud Infrastructure:2026年6月度サービス・アップデート
oracle4engineer
PRO
0
340
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
980
4 Signs Your Business is Dying
shpigford
187
22k
Docker and Python
trallard
47
3.9k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
750
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Scaling GitHub
holman
464
140k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
200
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 ?