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

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

Fd8ac25831e3e9cc7d70944c77a369ef?s=128

Nikolay Kuznetsov

November 07, 2019
Tweet

Transcript

  1. 1.

    TestContainers + JUnit 5 = elegant integration and e2e tests

    for microservices Nikolay Kuznetsov @nikolayk812 TESTING UNITED Vienna, 7 November 2019
  2. 2.

    About me • Go developer at Zalando Helsinki • Java

    developer at Infobip, DevExperts • C developer at Samsung, Motorola
  3. 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. 4.

    Key points • Targeting automated testing • Examples and demos

    in Java: TestContainers-Java, JUnit 5, Spring Boot • Principles are language-agnostic
  5. 8.
  6. 10.

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

    Vagrant • Docker, Docker Compose • Docker API
  7. 12.

    How to start a container for test? • Shell scripts

    • Maven plugin • Docker Compose • Docker API • MiniKube, Kubernetes
  8. 17.
  9. 19.

    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
  10. 22.
  11. 24.

    Readiness waiting strategies • Host port • HTTP status/body •

    Log message • Docker healthcheck • Combination of above • Custom
  12. 28.

    Demo recap • JUnit 5 integration via Extension API ◦

    @TestContainers / @Container • TestContainers Modules ◦ 14 databases ◦ Kafka, MockServer, LocalStack, ToxiProxy, etc
  13. 29.

    JUnit 5 Extensions • Customizable extension points: ◦ Life-cycle phases

    ◦ Parameter resolution ◦ Conditional execution, etc • Extension logic registered with @ExtendsWith
  14. 35.

    Why end-to-end testing? • Business flows across multiple services •

    Regression, when ◦ + new service ◦ - legacy service
  15. 37.

    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?
  16. 38.

    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?