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
370
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
320
JUGBB2020: Testcontainers - Past, Present, Future
bsideup
1
210
Presentation: Reactive: Do. Or do not. There is no try.
bsideup
1
1.2k
Devoxx MA: Testcontainers deep dive
bsideup
1
150
Jokerconf 2019: Testcontainers: a year-in-review
bsideup
1
290
GeekOut 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
730
DevClub Tallinn: How to Make Your OSS Project Successful
bsideup
1
630
Pivotal Toronto 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
100
GeeCON 2019: Testcontainers: a year-in-review
bsideup
1
2.5k
Other Decks in Programming
See All in Programming
生成AI時代のコンポーネントライブラリの作り方
touyou
1
220
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
130
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
5.8k
効率的な開発手段として VRTを活用する
ishkawa
0
140
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
1
150
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
390
5つのアンチパターンから学ぶLT設計
narihara
1
170
Team operations that are not burdened by SRE
kazatohiei
1
310
Is Xcode slowly dying out in 2025?
uetyo
1
270
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
130
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
524
40k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Producing Creativity
orderedlist
PRO
346
40k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
The World Runs on Bad Software
bkeepers
PRO
69
11k
The Invisible Side of Design
smashingmag
301
51k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
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