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

TestContainers + JUnit 5 = elegant integration...

TestContainers + JUnit 5 = elegant integration and e2e tests for microservices

Nikolay Kuznetsov

November 07, 2019
Tweet

More Decks by Nikolay Kuznetsov

Other Decks in Technology

Transcript

  1. TestContainers + JUnit 5 = elegant integration and e2e tests

    for microservices Nikolay Kuznetsov @nikolayk812 TESTING UNITED Vienna, 7 November 2019
  2. About me • Go developer at Zalando Helsinki • Java

    developer at Infobip, DevExperts • C developer at Samsung, Motorola
  3. My testing experience • Unit, integration and end-to-end automated tests

    development • Various organizational structures ◦ Separate QA teams ◦ QA engineers in a dev team ◦ No QA teams/engineers at all
  4. Key points • Targeting automated testing • Examples and demos

    in Java: TestContainers-Java, JUnit 5, Spring Boot • Principles are language-agnostic
  5. Integration testing evolution • In-memory mocking • Local DBs •

    Vagrant • Docker, Docker Compose • Docker API
  6. How to start a container for test? • Shell scripts

    • Maven plugin • Docker Compose • Docker API • MiniKube, Kubernetes
  7. TestContainers Java • github.com/testcontainers/testcontainers-java • Wraps docker-java library • Docker

    environment autodiscovery • Host port randomization • Containers clean up on JVM shutdown • Readiness waiting strategies
  8. Readiness waiting strategies • Host port • HTTP status/body •

    Log message • Docker healthcheck • Combination of above • Custom
  9. Demo recap • JUnit 5 integration via Extension API ◦

    @TestContainers / @Container • TestContainers Modules ◦ 14 databases ◦ Kafka, MockServer, LocalStack, ToxiProxy, etc
  10. JUnit 5 Extensions • Customizable extension points: ◦ Life-cycle phases

    ◦ Parameter resolution ◦ Conditional execution, etc • Extension logic registered with @ExtendsWith
  11. Why end-to-end testing? • Business flows across multiple services •

    Regression, when ◦ + new service ◦ - legacy service
  12. Testing against a deployed cluster • Deploy a new service

    version to the cluster? • Unexpected versions of dependent services • Unexpected database states ◦ Care to clear after the test? • Parallel CI builds?
  13. On-demand cluster for E2E tests + Locally and at CI

    machines + Control over dependent services versions - Time to start all containers - Resources: memory and CPU How to do it?