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
400
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TestContainers - integration testing without the hassle
Presented @ TopConf Tallinn
Sergei Egorov
November 16, 2016
More Decks by Sergei Egorov
See All by Sergei Egorov
SnowOne 2020: Jabel – retrofitting Java Compiler by instrumenting it!
bsideup
1
410
JUGBB2020: Testcontainers - Past, Present, Future
bsideup
1
260
Presentation: Reactive: Do. Or do not. There is no try.
bsideup
1
1.5k
Devoxx MA: Testcontainers deep dive
bsideup
1
200
Jokerconf 2019: Testcontainers: a year-in-review
bsideup
1
340
GeekOut 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
950
DevClub Tallinn: How to Make Your OSS Project Successful
bsideup
1
780
Pivotal Toronto 2019: Don’t be Homer Simpson with your Reactor!
bsideup
0
160
GeeCON 2019: Testcontainers: a year-in-review
bsideup
1
2.7k
Other Decks in Programming
See All in Programming
AIエージェント時代のコードレビューを設計する
nogu66
6
2.5k
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
140
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
110
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
140
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
0
220
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
0
410
What We Talk About When We Talk About XP
m_seki
2
350
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
140
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
660
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
160
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
500
業務時間外もAIに働いてもらう話
colorful12
3
9.9k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.4k
A Soul's Torment
seathinner
7
3.5k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
510
Writing Fast Ruby
sferik
630
63k
Prompt Engineering for Job Search
mfonobong
0
440
Documentation Writing (for coders)
carmenintech
77
5.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
260
Build your cross-platform service in a week with App Engine
jlugia
234
19k
What's in a price? How to price your products and services
michaelherold
247
13k
Tell your own story through comics
letsgokoyo
1
1.1k
We Are The Robots
honzajavorek
0
330
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