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
Self-Contained integration tests with Docker an...
Search
Michael Vitz
September 07, 2018
Programming
1
220
Self-Contained integration tests with Docker and Testcontainers
Michael Vitz
September 07, 2018
Tweet
Share
More Decks by Michael Vitz
See All by Michael Vitz
Spring Boot entzaubert
michaelvitz
0
82
JCON 2020: Java & Spring Boot im Container
michaelvitz
0
210
Java & Spring Boot im Container
michaelvitz
0
260
Geektastic Connect: Einführung in Web-Components
michaelvitz
0
78
JVM-Con 2019: Einführung in Web-Components
michaelvitz
0
100
JCON 2019: Einführung in Web-Components
michaelvitz
1
180
Neues von Java und dem JDK
michaelvitz
2
110
Spring Boot entzaubert
michaelvitz
0
300
Geektastic Connect: Neues von Java und dem JDK
michaelvitz
0
150
Other Decks in Programming
See All in Programming
サーバーサイドのビルド時間87倍高速化
plaidtech
PRO
0
690
rage against annotate_predecessor
junk0612
0
150
tool ディレクティブを導入してみた感想
sgash708
1
160
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
0
220
LLMOpsのパフォーマンスを支える技術と現場で実践した改善
po3rin
8
1k
SOCI Index Manifest v2が出たので調べてみた / Introduction to SOCI Index Manifest v2
tkikuc
1
120
TROCCO×dbtで実現する人にもAIにもやさしいデータ基盤
nealle
0
390
ライブ配信サービスの インフラのジレンマ -マルチクラウドに至ったワケ-
mirrativ
2
270
レガシープロジェクトで最大限AIの恩恵を受けられるようClaude Codeを利用する
tk1351
4
1.5k
Protocol Buffersの型を超えて拡張性を得る / Beyond Protocol Buffers Types Achieving Extensibility
linyows
0
100
Google I/O recap web編 大分Web祭り2025
kponda
0
2.9k
オープンセミナー2025@広島LT技術ブログを続けるには
satoshi256kbyte
0
150
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
910
Become a Pro
speakerdeck
PRO
29
5.5k
Making Projects Easy
brettharned
117
6.4k
Statistics for Hackers
jakevdp
799
220k
Code Review Best Practice
trishagee
70
19k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
185
54k
Being A Developer After 40
akosma
90
590k
Code Reviewing Like a Champion
maltzj
525
40k
We Have a Design System, Now What?
morganepeng
53
7.8k
The Pragmatic Product Professional
lauravandoore
36
6.8k
Transcript
2018-09-07 Berlin / BED-Con Self-Contained integration tests with Docker and
Testcontainers Michael Vitz https://pixabay.com/en/construction-site-crane-pier-1156575 @michaelvitz #bedcon
Michael Vitz Senior Consultant at INNOQ • Build, run, and
maintain JVM applications • JavaSPEKTRUM column owner • ❤ Clojure
www.innoq.com OFFICES Monheim Berlin Offenbach Munich Zurich FACTS ~125 employees
Privately owned Vendor-independent SERVICES Strategy & technology consulting Digital business models Software architecture & development Digital platforms & infrastructures Knowledge transfer, coaching & trainings CLIENTS Finance Telecommunications Logistics E-commerce Fortune 500 SMBs Startups
None
None
UI Integrated UI Service Service Integration Unit Implementation Unit
UI Integrated UI Service Service Integration Unit Implementation Unit https://martinfowler.com/bliki/TestPyramid.html
https://www.thoughtworks.com/de/insights/blog/introducing-software-testing-cupcake-anti-pattern https://labs.spotify.com/2018/01/11/testing-of-microservices Testing Pyramid Honeycomb Ice Cream Cone
None
https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html Ports-And-Adapters
None
Testcontainers • Launch Docker containers from Java • Test data
access layer • UI browser tests • Requires Docker • Requires Java 8 https://www.testcontainers.org
@ClassRule public static GenericContainer postgres = new GenericContainer("postgres:latest") .withEnv("POSTGRES_PASSWORD", "mysecretpassword");
private Connection create() throws Exception { String host = postgres.getContainerIpAddress(); int port = postgres.getMappedPort(5432); String url = "jdbc:postgresql://"+host+":"+port+"/postgres"; String user = "postgres"; String password = "mysecretpassword"; return DriverManager.getConnection(url, user, password); } Generic Containers
static String WAIT_PATTERN = ".*database system is ready to accept
connections.*\\s"; @ClassRule public static GenericContainer postgres = new GenericContainer("postgres:latest") .withEnv("POSTGRES_PASSWORD", "mysecretpassword") .waitingFor(forLogMessage(WAIT_PATTERN, 2)); Container != Application
@ClassRule public static PostgreSQLContainer postgres = new PostgreSQLContainer() .withPassword("mysecretpassword"); private
Connection create() throws Exception { String url = postgres.getJdbcUrl(); String user = postgres.getUsername(); String password = postgres.getPassword(); return DriverManager.getConnection(url, user, password); } Database Container
@Rule public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer() .withDesiredCapabilities(DesiredCapabilities.chrome()) .withRecordingMode(RECORD_ALL, new
File("build")); @Test public void test() { WebDriver driver = chrome.getWebDriver(); } Selenium Container
Testcontainers 2.0 • Cleanup API • Entangle from JUnit 4
rules https://github.com/rnorth/containercore/pull/1
www.innoq.com innoQ Deutschland GmbH Krischerstr. 100 40789 Monheim am Rhein
Germany +49 2173 3366-0 Ohlauer Str. 43 10999 Berlin Germany +49 2173 3366-0 Ludwigstr. 180E 63067 Offenbach Germany +49 2173 3366-0 Kreuzstr. 16 80331 München Germany +49 2173 3366-0 innoQ Schweiz GmbH Gewerbestr. 11 CH-6330 Cham Switzerland +41 41 743 0116 Thanks! Questions? Michael Vitz michael.vitz@innoq.com michaelvitz +49 151 19116015 https://speakerdeck.com/michaelvitz/testcontainers https://github.com/mvitz/javaspektrum-testcontainers