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
360
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
300
JUGBB2020: Testcontainers - Past, Present, Future
bsideup
1
190
Presentation: Reactive: Do. Or do not. There is no try.
bsideup
1
1.2k
Devoxx MA: Testcontainers deep dive
bsideup
1
140
Jokerconf 2019: Testcontainers: a year-in-review
bsideup
1
290
GeekOut 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
690
DevClub Tallinn: How to Make Your OSS Project Successful
bsideup
1
580
Pivotal Toronto 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
86
GeeCON 2019: Testcontainers: a year-in-review
bsideup
1
2.5k
Other Decks in Programming
See All in Programming
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
110
Pulsar2 を雰囲気で使ってみよう
anoken
0
240
JavaScriptツール群「UnJS」を5分で一気に駆け巡る!
k1tikurisu
9
1.8k
Linux && Docker 研修/Linux && Docker training
forrep
24
4.5k
ML.NETで始める機械学習
ymd65536
0
120
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
370
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
150
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
230
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
130
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
5
390
動作確認やテストで漏れがちな観点3選
starfish719
6
1k
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
660
Featured
See All Featured
A designer walks into a library…
pauljervisheath
205
24k
Being A Developer After 40
akosma
89
590k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Statistics for Hackers
jakevdp
797
220k
Faster Mobile Websites
deanohume
306
31k
Navigating Team Friction
lara
183
15k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
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