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 - integration testing without th...
Search
Sergei Egorov
November 16, 2016
Programming
1
380
TestContainers - integration testing without the hassle
Presented @ TopConf Tallinn
Sergei Egorov
November 16, 2016
Tweet
Share
More Decks by Sergei Egorov
See All by Sergei Egorov
SnowOne 2020: Jabel – retrofitting Java Compiler by instrumenting it!
bsideup
1
340
JUGBB2020: Testcontainers - Past, Present, Future
bsideup
1
210
Presentation: Reactive: Do. Or do not. There is no try.
bsideup
1
1.3k
Devoxx MA: Testcontainers deep dive
bsideup
1
160
Jokerconf 2019: Testcontainers: a year-in-review
bsideup
1
300
GeekOut 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
740
DevClub Tallinn: How to Make Your OSS Project Successful
bsideup
1
640
Pivotal Toronto 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
110
GeeCON 2019: Testcontainers: a year-in-review
bsideup
1
2.6k
Other Decks in Programming
See All in Programming
アセットのコンパイルについて
ojun9
0
120
奥深くて厄介な「改行」と仲良くなる20分
oguemon
1
510
ユーザーも開発者も悩ませない TV アプリ開発 ~Compose の内部実装から学ぶフォーカス制御~
taked137
0
140
速いWebフレームワークを作る
yusukebe
5
1.7k
Laravel Boost 超入門
fire_arlo
2
210
Amazon RDS 向けに提供されている MCP Server と仕組みを調べてみた/jawsug-okayama-2025-aurora-mcp
takahashiikki
1
110
Compose Multiplatform × AI で作る、次世代アプリ開発支援ツールの設計と実装
thagikura
0
130
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
0
110
[FEConf 2025] 모노레포 절망편, 14개 레포로 부활하기까지 걸린 1년
mmmaxkim
0
1.6k
「待たせ上手」なスケルトンスクリーン、 そのUXの裏側
teamlab
PRO
0
480
AWS発のAIエディタKiroを使ってみた
iriikeita
1
180
Performance for Conversion! 分散トレーシングでボトルネックを 特定せよ
inetand
0
120
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
13k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
What's in a price? How to price your products and services
michaelherold
246
12k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
187
55k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.9k
How to Ace a Technical Interview
jacobian
279
23k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Typedesign – Prime Four
hannesfritz
42
2.8k
Transcript
TestContainers Integration testing without the hassle Sergei @bsideup Egorov
Integration testing Why it matters?
Verify how your software product will behave in real-world conditions
Isolated from other system components to avoid false negatives
Real: databases, file systems, network interfaces, …
Grey box testing - we know some inner details, but
mostly use public APIs
None
Unit testing • Simulation tests are green, yay! • Everything
is mocked • DB is written by others, why should I test it?
Integration testing https://commons.wikimedia.org/wiki/File:Cd4007.jpg • Jeez, how did it passed the
Unit testing? • Is it a smoke? @#$%! YES IT IS! • Who knew that 100w soldering gun was a bit too powerful for it?
System testing https://commons.wikimedia.org/wiki/File:UART_8250_Microchip.jpg • Takes a lot of time to
solder • “Oh no, the power bus is too far away from my microchip!” • Interference between the components
Production
Integration testing Real-world, but isolated testing Spot the issues before
the real environment Can be run during the development You have to start real databases Should be cross-platform Slower than Unit testing Pros Cons
Obvious solution
None
Abstraction layer
CI friendly
Cross-platform
Docker Compose FTW! redis: image: redis ports: - "6379:6379" postgres:
image: postgres ports: - "5432:5432" elasticsearch: image: elasticsearch:5.0.0 ports: - "9200:9200"
But…
No ports randomization redis: image: redis ports: - "6379:6379" postgres:
image: postgres ports: - "5432:5432" elasticsearch: image: elasticsearch:5.0.0 ports: - "9200:9200"
Fighting with Docker environment
There is no place like
There is no place like Except Docker Machine
Can we improve that?
None
Remove the database
Remove the database
None
As simple as PostgreSQLContainer postgresql = new PostgreSQLContainer() GenericContainer
redis = new GenericContainer("redis:3") .withExposedPorts(6379)
TestContainers • https://github.com/testcontainers/testcontainers-java • OSS project by Richard North, supported
by ZeroTurnaround • Declarative Docker Java API wrapper • JUnit rules, can be used with other frameworks like TestNG, Cucumber, etc…
How it works • Wraps https://github.com/docker-java/docker-java • Docker environment discovery
• Will start docker-machine if it’s not started yet • Docker for Mac support • Containers cleanup on JVM shutdown
Use case #1: testing of microservices • REST service •
Java, Spring Boot • Redis and PostgreSQL • Calls some other micro-services
Demo
Use case #2: Docker as Selenium driver • Selenium/Selenide tests
• No need to install Chrome/Firefox/etc • CI friendly
Demo
Use case #3: Java agent testing • Test different Java
versions • Simplify I/O testing • The actual reason why ZeroTurnaround decided to use TestContainers :)
Demo