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 + JUnit 5 = elegant integration...
Search
Nikolay Kuznetsov
November 07, 2019
Technology
2
290
TestContainers + JUnit 5 = elegant integration and e2e tests for microservices
Nikolay Kuznetsov
November 07, 2019
Tweet
Share
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
Integration testing with TestСontainers-Go
nikolayk812
0
120
Integration testing with TestContainers-Go
nikolayk812
0
220
Integration testing with TestСontainers and JUnit 5
nikolayk812
0
160
Integration and end-to-end testing with TestСontainers
nikolayk812
0
96
Integration and end-to-end testing with TestСontainers
nikolayk812
0
18
Other Decks in Technology
See All in Technology
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
350
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
610
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
9
1k
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
The Rise of LLMOps
asei
7
1.6k
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
520
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
230
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
For a Future-Friendly Web
brad_frost
175
9.4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Embracing the Ebb and Flow
colly
84
4.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Transcript
TestContainers + JUnit 5 = elegant integration and e2e tests
for microservices Nikolay Kuznetsov @nikolayk812 TESTING UNITED Vienna, 7 November 2019
About me • Go developer at Zalando Helsinki • Java
developer at Infobip, DevExperts • C developer at Samsung, Motorola
My testing experience • Unit, integration and end-to-end automated tests
development • Various organizational structures ◦ Separate QA teams ◦ QA engineers in a dev team ◦ No QA teams/engineers at all
Key points • Targeting automated testing • Examples and demos
in Java: TestContainers-Java, JUnit 5, Spring Boot • Principles are language-agnostic
Why integration testing?
2 unit tests, 0 integration tests
Tests trade-offs
None
Basic integration test
Integration testing evolution • In-memory mocking • Local DBs •
Vagrant • Docker, Docker Compose • Docker API
Docker architecture
How to start a container for test? • Shell scripts
• Maven plugin • Docker Compose • Docker API • MiniKube, Kubernetes
Shell scripts
Maven plugin github.com/fabric8io/docker-maven-plugin
Docker Compose
Docker API
None
TestContainers flavors
TestContainers Java • github.com/testcontainers/testcontainers-java • Wraps docker-java library • Docker
environment autodiscovery • Host port randomization • Containers clean up on JVM shutdown • Readiness waiting strategies
As simple as var redis = new GenericContainer("redis:5.0.5") .withExposedPorts(6379); var
postgres = new PostgreSQLContainer();
Docker environment autodiscovery
Host port randomization • Prevents port conflicts • Enables parallel
CI builds • API to get an actual host port
Containers cleanup github.com/testcontainers/moby-ryuk
Readiness waiting strategies • Host port • HTTP status/body •
Log message • Docker healthcheck • Combination of above • Custom
Demo setup User Service
Demo scenario User Service INSERT INTO SELECT FROM
Demo github.com/nikolayk812/tu-tc-demo
Demo recap • JUnit 5 integration via Extension API ◦
@TestContainers / @Container • TestContainers Modules ◦ 14 databases ◦ Kafka, MockServer, LocalStack, ToxiProxy, etc
JUnit 5 Extensions • Customizable extension points: ◦ Life-cycle phases
◦ Parameter resolution ◦ Conditional execution, etc • Extension logic registered with @ExtendsWith
github.com/nikolayk812/tu-tc-demo Demo-2: setup User Service
Demo-2: scenario User Service POST /users GET /user/<id>
Demo-2: Docker network User Service user-alias: 8083 postgres-alias: 5432 localhost:
32812
Demo 2 github.com/nikolayk812/tu-tc-demo
Demo-2: recap • Docker network and alias
Why end-to-end testing? • Business flows across multiple services •
Regression, when ◦ + new service ◦ - legacy service
Testing/staging deployed cluster Spring Cloud Kubernetes
Testing against a deployed cluster • Deploy a new service
version to the cluster? • Unexpected versions of dependent services • Unexpected database states ◦ Care to clear after the test? • Parallel CI builds?
On-demand cluster for E2E tests + Locally and at CI
machines + Control over dependent services versions - Time to start all containers - Resources: memory and CPU How to do it?
Kubernetes for E2E tests?
Kubernetes for E2E tests - YAGNI TestContainers + Docker network!
E2E test setup User Service Item Service
Takeaways • https://testcontainers.org • Balance between flexibility, speed and features
• Works on Mac, Linux, Windows
QUESTIONS ?