Integration and end-to-end testing with TestСontainers

Integration and end-to-end testing with TestСontainers

Fd8ac25831e3e9cc7d70944c77a369ef?s=128

Nikolay Kuznetsov

June 26, 2019
Tweet

Transcript

  1. Integration and end-to-end testing with TestСontainers Nikolay Kuznetsov @nikolayk812 ContainerDays,

    Hamburg, 26 June 2019
  2. About me • Go developer at Zalando Helsinki • Java

    developer at Infobip, DevExperts • C developer at Samsung, Motorola
  3. Why integration testing?

  4. Trade-offs Test Runtime

  5. Integration testing evolution • In-memory mocking • Local DBs •

    Vagrant • Docker, Docker Compose • Docker API
  6. How to start Docker containers for integration test? • Shell

    scripts • Maven plugin • Docker Compose • … • MiniKube, Kubernetes
  7. Shell scripts

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

  9. Docker Compose

  10. None
  11. TestContainers • github.com/testcontainers/testcontainers-java • Wraps docker-java library • Docker environment

    discovery • Host port randomization • Containers clean up on JVM shutdown • Waiting strategies
  12. As simple as static PostgreSQLContainer postgres = new PostgreSQLContainer(); static

    GenericContainer redis = new GenericContainer("redis:5.0.5") .withExposedPorts(6379);
  13. Docker environment discovery

  14. Host port randomization • To prevent port conflicts • Enables

    parallel builds • API to get a host port
  15. Containers cleanup https://github.com/testcontainers/moby-ryuk

  16. Waiting strategies

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

  18. 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
  19. E2E setup Item Service User Service Spring Cloud Netflix Eureka

  20. None
  21. Demo github.com/nikolayk812/cd-tc-demo

  22. Hints • Host port forwarding Testcontainers.exposeHostPorts() • Fixed host port

    for remote debug GenericContainer.addFixedExposedPort() • Disable Ryuk set env TESTCONTAINERS_RYUK_DISABLED=true
  23. Alternatives to E2E testing Goal is to minimize chances of

    breaking production • Staging environments Handling team boundaries? • Canary deployment • Contract testing Spring Cloud Contract
  24. Modules • 10+ DB modules • MockServer • LocalStack =

    Atlassian’s local AWS cloud stack • Toxiproxy • Kafka
  25. Takeaways • https://testcontainers.org • Balance between flexibility, speed and features

    • Works on Mac, Linux, Windows
  26. Thank you! @nikolayk812 nikolayk812