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
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