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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Michael Vitz
September 07, 2018
Programming
250
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Self-Contained integration tests with Docker and Testcontainers
Michael Vitz
September 07, 2018
More Decks by Michael Vitz
See All by Michael Vitz
Spring Boot entzaubert
michaelvitz
0
110
JCON 2020: Java & Spring Boot im Container
michaelvitz
0
210
Java & Spring Boot im Container
michaelvitz
0
310
Geektastic Connect: Einführung in Web-Components
michaelvitz
0
110
JVM-Con 2019: Einführung in Web-Components
michaelvitz
0
120
JCON 2019: Einführung in Web-Components
michaelvitz
1
200
Neues von Java und dem JDK
michaelvitz
2
140
Spring Boot entzaubert
michaelvitz
0
330
Geektastic Connect: Neues von Java und dem JDK
michaelvitz
0
180
Other Decks in Programming
See All in Programming
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
150
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
140
継続モナドとリアクティブプログラミング
yukikurage
3
560
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
220
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
170
関数型プログラミングのメリットって何だろう?
wanko_it
0
170
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.4k
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
5.8k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
130
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
140
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
The Cult of Friendly URLs
andyhume
79
6.9k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Building an army of robots
kneath
306
46k
Raft: Consensus for Rubyists
vanstee
141
7.6k
How to Talk to Developers About Accessibility
jct
2
360
Building Applications with DynamoDB
mza
96
7.1k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Tell your own story through comics
letsgokoyo
1
990
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
How GitHub (no longer) Works
holman
316
150k
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
[email protected]
michaelvitz +49 151 19116015 https://speakerdeck.com/michaelvitz/testcontainers https://github.com/mvitz/javaspektrum-testcontainers