Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

Nikolay Kuznetsov

June 26, 2019
Tweet

More Decks by Nikolay Kuznetsov

Other Decks in Programming

Transcript

  1. About me • Go developer at Zalando Helsinki • Java

    developer at Infobip, DevExperts • C developer at Samsung, Motorola
  2. Integration testing evolution • In-memory mocking • Local DBs •

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

    scripts • Maven plugin • Docker Compose • … • MiniKube, Kubernetes
  4. TestContainers • github.com/testcontainers/testcontainers-java • Wraps docker-java library • Docker environment

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

    GenericContainer redis = new GenericContainer("redis:5.0.5") .withExposedPorts(6379);
  6. Host port randomization • To prevent port conflicts • Enables

    parallel builds • API to get a host port
  7. 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
  8. Hints • Host port forwarding Testcontainers.exposeHostPorts() • Fixed host port

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

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

    Atlassian’s local AWS cloud stack • Toxiproxy • Kafka