Slide 1

Slide 1 text

Testcontainers made easy Álvaro Sánchez-Mariscal Principal Member of Technical Staff Oracle @alvaro_sanchez

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

@alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 3 Slides available on Speaker Deck

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Copyright © 2024, Oracle and/or its affiliates 5 By Spotify The Test Honeycomb https://engineering.atspotify.com/2018/01/testing-of-microservices/ Integrated Integration

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

@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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

@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.

Slide 11

Slide 11 text

@alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 11 Official modules

Slide 12

Slide 12 text

@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.

Slide 13

Slide 13 text

@alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 13 Testcontainers Desktop

Slide 14

Slide 14 text

@alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 14 Testcontainers Cloud

Slide 15

Slide 15 text

Copyright © 2024, Oracle and/or its affiliates 15 Testcontainers in a Java project Demo

Slide 16

Slide 16 text

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.

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

@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

Slide 19

Slide 19 text

@alvaro_sanchez Copyright © 2024, Oracle and/or its affiliates 19 Architecture

Slide 20

Slide 20 text

Copyright © 2024, Oracle and/or its affiliates 20 Micronaut Test Resources Demo

Slide 21

Slide 21 text

@alvaro_sanchez Q&A Copyright © 2024, Oracle and/or its affiliates 21

Slide 22

Slide 22 text

Álvaro Sánchez-Mariscal @alvaro_sanchez

Slide 23

Slide 23 text

No content