Slide 1

Slide 1 text

Integration and end-to-end testing with TestСontainers Nikolay Kuznetsov @nikolayk812 ContainerDays, Hamburg, 26 June 2019

Slide 2

Slide 2 text

About me ● Go developer at Zalando Helsinki ● Java developer at Infobip, DevExperts ● C developer at Samsung, Motorola

Slide 3

Slide 3 text

Why integration testing?

Slide 4

Slide 4 text

Trade-offs Test Runtime

Slide 5

Slide 5 text

Integration testing evolution ● In-memory mocking ● Local DBs ● Vagrant ● Docker, Docker Compose ● Docker API

Slide 6

Slide 6 text

How to start Docker containers for integration test? ● Shell scripts ● Maven plugin ● Docker Compose ● … ● MiniKube, Kubernetes

Slide 7

Slide 7 text

Shell scripts

Slide 8

Slide 8 text

Maven plugins github.com/fabric8io/docker-maven-plugin

Slide 9

Slide 9 text

Docker Compose

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

TestContainers ● github.com/testcontainers/testcontainers-java ● Wraps docker-java library ● Docker environment discovery ● Host port randomization ● Containers clean up on JVM shutdown ● Waiting strategies

Slide 12

Slide 12 text

As simple as static PostgreSQLContainer postgres = new PostgreSQLContainer(); static GenericContainer redis = new GenericContainer("redis:5.0.5") .withExposedPorts(6379);

Slide 13

Slide 13 text

Docker environment discovery

Slide 14

Slide 14 text

Host port randomization ● To prevent port conflicts ● Enables parallel builds ● API to get a host port

Slide 15

Slide 15 text

Containers cleanup https://github.com/testcontainers/moby-ryuk

Slide 16

Slide 16 text

Waiting strategies

Slide 17

Slide 17 text

Demo github.com/nikolayk812/cd-tc-demo

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

E2E setup Item Service User Service Spring Cloud Netflix Eureka

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Demo github.com/nikolayk812/cd-tc-demo

Slide 22

Slide 22 text

Hints ● Host port forwarding Testcontainers.exposeHostPorts() ● Fixed host port for remote debug GenericContainer.addFixedExposedPort() ● Disable Ryuk set env TESTCONTAINERS_RYUK_DISABLED=true

Slide 23

Slide 23 text

Alternatives to E2E testing Goal is to minimize chances of breaking production ● Staging environments Handling team boundaries? ● Canary deployment ● Contract testing Spring Cloud Contract

Slide 24

Slide 24 text

Modules ● 10+ DB modules ● MockServer ● LocalStack = Atlassian’s local AWS cloud stack ● Toxiproxy ● Kafka

Slide 25

Slide 25 text

Takeaways ● https://testcontainers.org ● Balance between flexibility, speed and features ● Works on Mac, Linux, Windows

Slide 26

Slide 26 text

Thank you! @nikolayk812 nikolayk812