$30 off During Our Annual Pro Sale. View Details »

Testcontainers made easy

Testcontainers made easy

estcontainers is an open-source framework for providing throwaway, lightweight instances of databases, message brokers, web browsers, or just about anything that can run in a Docker container. Integrated with test frameworks such as JUnit and Spock, it simplifies the same system in production and during tests, so it's no longer needed to use something like H2 for tests.

Micronaut takes Testcontainers further, eliminating the need of actually using the Testcontainers API. It will provision the test resource automatically for both development mode and testing.

In this session, Micronaut committer Álvaro Sánchez-Mariscal will demonstrate with examples how Micronaut Test Resources works, and how this integration dramatically improves the developer experience.

Álvaro Sánchez-Mariscal

September 11, 2024
Tweet

More Decks by Álvaro Sánchez-Mariscal

Other Decks in Programming

Transcript

  1. Copyright © 2024, Oracle and/or its affiliates 2 About me

    • Coming from Madrid • Developer since 2001 (Java stack) • Micronaut core developer since its inception (2017). • Author: Maven Plugin, Object Storage, Kubernetes, Cache, Control Panel. • Others: Core, Gradle, AWS, GCP, Azure, Security, Test, etc. • Currently at Oracle Labs: • Micronaut and Graal Development Kit for Micronaut (GDK). • GraalVM Native Build Tools. @alvaro_sanchez
  2. Copyright © 2024, Oracle and/or its affiliates 4 By Martin

    Fowler The Test Pyramid https://martinfowler.com/bliki/TestPyramid.html E2E Integration Unit
  3. Copyright © 2024, Oracle and/or its affiliates 5 By Spotify

    The Test Honeycomb https://engineering.atspotify.com/2018/01/testing-of-microservices/ Integrated Integration
  4. @alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 6 Unit

    testing Image source: https://martinfowler.com/articles/practical-test-pyramid.html
  5. @alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 7 End-to-end

    testing Image source: https://martinfowler.com/articles/practical-test-pyramid.html
  6. @alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 8 Integration

    testing Image source: https://martinfowler.com/articles/practical-test-pyramid.html In-memory DB
  7. @alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 9 Integration

    testing Images source: https://martinfowler.com/articles/practical-test-pyramid.html
  8. @alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 10 Testcontainers

    • Library for managing Docker containers to wrap real services for integration testing. • Supports multiple languages. • Testcontainers-Java: • Integrates with Junit and Spock. • First-class support from Spring, Quarkus and Micronaut.
  9. @alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 12 Testcontainers

    features • Manages the container lifecycle. • Allows networking configuration. • Can execute commands inside the started container. • Is able to copy files to containers. • Can create images on-the-fly (from a Dockerfile or using Jib). • Handles reusable containers.
  10. Introduction to Micronaut Copyright © 2024, Oracle and/or its affiliates

    16 Micronaut is a complete solution for any type of application: microservices, message-driven producers or consumers, command-line apps, serverless functions, etc. All application types Micronaut leverages Java annotation processors and other optimisations to compute the framework infrastructure at compile-time, drastically reducing startup time and memory consumption. Highly optimised Modern, open-source Java Framework Micronaut has been designed from scratch in 2017, focused on modern architectures like microservices and serverless, and with the cloud in mind.
  11. Micronaut computes at build time: • All dependency and configuration

    injection. • Annotation metadata (meta annotations) • AOP proxies. • Bean introspections. • All other framework infrastructure. At runtime: • No reflection. • No proxy generation. • No dynamic classloading. • No classpath scanning. AOT: Ahead Of Time Copyright © 2024, Oracle and/or its affiliates 17 Source code @Singleton class MySvc {} Bytecode class $MySvc$Definition {} class $MySvc$Definition$Reference {} Source code @Builder record Person() {} Source code @Generated class PersonBuilder() {} compilation compilation
  12. @alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 18 Micronaut

    Test Resources • Automatic provisioning of external resources needed during development or testing. • Built-in support: • Integrated with JUnit Platform (JUnit / Spock / Kotest) for zero-configuration Testcontainers. • MariaDB • MySQL • Oracle • PostgreSQL • SQL Server • Elasticsearch • Redis • MongoDB • Neo4j • Hashicorp Vault • Kafka • RabbitMQ • MQTT • Localstack • Anything else Testcontainers supports