Speaker Deck
Speaker Deck Pro
Sign in
Sign up
for free
Integration and end-to-end testing with TestСontainers
Nikolay Kuznetsov
June 26, 2019
Programming
0
6
Integration and end-to-end testing with TestСontainers
Nikolay Kuznetsov
June 26, 2019
Tweet
Share
More Decks by Nikolay Kuznetsov
See All by Nikolay Kuznetsov
nikolayk812
0
110
nikolayk812
0
77
nikolayk812
0
120
nikolayk812
0
50
nikolayk812
0
46
Other Decks in Programming
See All in Programming
kazuki19992
0
440
nrslib
20
13k
viteinfinite
0
140
xrdnk
0
130
junmikai
0
280
momofff
0
160
yshrsmz
1
450
wasabeef
1
560
nanimonodemonai
2
1.4k
osyo
1
360
masayaaoyama
4
520
hirotokirimaru
1
390
Featured
See All Featured
andyhume
62
3.3k
lynnandtonic
270
16k
rasmusluckow
318
18k
productmarketing
5
640
jasonvnalue
82
8k
vanstee
116
4.8k
brianwarren
83
4.7k
chriscoyier
499
130k
frogandcode
127
20k
zakiwarfel
88
3.3k
jnunemaker
PRO
40
4.5k
trallard
13
640
Transcript
Integration and end-to-end testing with TestСontainers Nikolay Kuznetsov @nikolayk812 ContainerDays,
Hamburg, 26 June 2019
About me • Go developer at Zalando Helsinki • Java
developer at Infobip, DevExperts • C developer at Samsung, Motorola
Why integration testing?
Trade-offs Test Runtime
Integration testing evolution • In-memory mocking • Local DBs •
Vagrant • Docker, Docker Compose • Docker API
How to start Docker containers for integration test? • Shell
scripts • Maven plugin • Docker Compose • … • MiniKube, Kubernetes
Shell scripts
Maven plugins github.com/fabric8io/docker-maven-plugin
Docker Compose
None
TestContainers • github.com/testcontainers/testcontainers-java • Wraps docker-java library • Docker environment
discovery • Host port randomization • Containers clean up on JVM shutdown • Waiting strategies
As simple as static PostgreSQLContainer postgres = new PostgreSQLContainer(); static
GenericContainer redis = new GenericContainer("redis:5.0.5") .withExposedPorts(6379);
Docker environment discovery
Host port randomization • To prevent port conflicts • Enables
parallel builds • API to get a host port
Containers cleanup https://github.com/testcontainers/moby-ryuk
Waiting strategies
Demo github.com/nikolayk812/cd-tc-demo
Why end-to-end testing? • Test business flows which go through
multiple microservices before production deployment • Replace a legacy service with a new implementation, make sure business flows hold
E2E setup Item Service User Service Spring Cloud Netflix Eureka
None
Demo github.com/nikolayk812/cd-tc-demo
Hints • Host port forwarding Testcontainers.exposeHostPorts() • Fixed host port
for remote debug GenericContainer.addFixedExposedPort() • Disable Ryuk set env TESTCONTAINERS_RYUK_DISABLED=true
Alternatives to E2E testing Goal is to minimize chances of
breaking production • Staging environments Handling team boundaries? • Canary deployment • Contract testing Spring Cloud Contract
Modules • 10+ DB modules • MockServer • LocalStack =
Atlassian’s local AWS cloud stack • Toxiproxy • Kafka
Takeaways • https://testcontainers.org • Balance between flexibility, speed and features
• Works on Mac, Linux, Windows
Thank you! @nikolayk812 nikolayk812