Slide 1

Slide 1 text

Hugo Guerrero API Testing and Mocking with TestContainers

Slide 2

Slide 2 text

@MICROCKSIO Hugo Guerrero Mexican @ MA, USA @hguerreroo Event-Driven APIs Specialist Open Source Advocate History, Travel & Food Enthusiast #JCONFDEV24

Slide 3

Slide 3 text

@MICROCKSIO @MICROCKSIO #APIDAYS Distributed systems!

Slide 4

Slide 4 text

@MICROCKSIO #JCONFDEV24 Distributed systems! v2.3.1 v2.3.1 v2.3.1 v2.3.1 v2.3.1 v2.3.1

Slide 5

Slide 5 text

@MICROCKSIO #JCONFDEV24 We are building microservices, right?

Slide 6

Slide 6 text

@MICROCKSIO #JCONFDEV24 Distributed systems with decoupling! v2.3.1 v1.2.3 v25.8 v2.8 v3.2.1 v5.7.0

Slide 7

Slide 7 text

@MICROCKSIO #JCONFDEV24 Inner dev/test loop can be painful with microservices and Kubernetes.

Slide 8

Slide 8 text

@MICROCKSIO Integration Testing #JCONFDEV24 Usually means “integration testing environment”: - Shared Instances - Local Installation - In memory solutions - Docker compose Everything up an running before running test.

Slide 9

Slide 9 text

@MICROCKSIO Needs for Shifting Left µS A Redis 🔌 REST API A 🔌 REST API C µS B 🔌 REST API B 🔌 gRPC svc D Multiplicity of stacks, of middlewares and APIs make things difficult to setup, test and validate during development on the laptop (the inner loop) #JCONFDEV24

Slide 10

Slide 10 text

@MICROCKSIO #JCONFDEV24 Testcontainers 🧊 @MICROCKSIO

Slide 11

Slide 11 text

@MICROCKSIO Testcontainers #JCONFDEV24 - Creates a reliable environment for running tests. - It's a library, ported to multiple languages - Dockerizes common test dependencies - Ability to run custom Dockerfiles when needed. - Flexible enough to manage the container lifecycle and advanced networking - https://github.com/testcontainers

Slide 12

Slide 12 text

@MICROCKSIO #JCONFDEV24 Testcontainers 🧊 workflow @MICROCKSIO

Slide 13

Slide 13 text

@MICROCKSIO #JCONFDEV24 @MICROCKSIO Docker/AtomicJar partners with so ware vendors to maintain and certify official modules. Java, NodeJS, Go, …

Slide 14

Slide 14 text

@MICROCKSIO Testcontainers-Java #JCONFDEV24 - Created 7 years ago - Uses docker-java API - Integrates with Frameworks, like JUnit - Works with anything that runs in a container

Slide 15

Slide 15 text

@MICROCKSIO https://microcks.io #JCONFDEV24

Slide 16

Slide 16 text

@MICROCKSIO @MICROCKSIO #JCONFDEV24 turns your artifacts into mocks in seconds INGEST PROVIDE MOCKS WELL-KNOWN ARTIFACTS SMART MOCKS API Consumer and others

Slide 17

Slide 17 text

@MICROCKSIO @MICROCKSIO #JCONFDEV24 Ensure your implementation is conformant INGEST WELL-KNOWN ARTIFACTS AUTOMATIC TEST SUITE and others VALIDATE REAL API API v1.2 API v1.1 API v1.0 API Provider

Slide 18

Slide 18 text

@MICROCKSIO Microcks Testcontainers Java #JCONFDEV24 Java library for Testcontainers that enables embedding Microcks into your JUnit tests with lightweight, throwaway instance thanks to containers

Slide 19

Slide 19 text

@MICROCKSIO Microcks Quarkus Extension #JCONFDEV24 Quarkus extension that enables embedding Microcks as a DevService managing mocks for dependencies and contract-testing your API endpoints

Slide 20

Slide 20 text

@MICROCKSIO Microcks Quarkus Extension #JCONFDEV24

Slide 21

Slide 21 text

#JCONFDEV24 @MICROCKSIO Demo Time Photo by Unsplash

Slide 22

Slide 22 text

Let’s imagine … 🍰 🎂 🧁 🍩 @MICROCKSIO #JCONFDEV24 # price is a number # name, price & status are mandatory { "name": "Millefeuille", "description": "Delicieux Millefeuille gourmand", "size": "L", "price": 4.4, "status": "available" } # List pastries by size GET /pastry?size=M [...] # Pastries having M size # Get pastry details GET /pastry/Millefeuille {...} # Millefeuille pastry # Patch a pastry price PATCH /pastry/Millefeuille -d {"price": 4.5} {...} # Pastry with new price

Slide 23

Slide 23 text

@MICROCKSIO Let’s imagine … 🍰 🎂 🧁 🍩 @MICROCKSIO #JCONFDEV24 Product Domain Pastry API Order Domain Order Service Stores Partners Online Retrieve Place orders

Slide 24

Slide 24 text

#JCONFDEV24 @MICROCKSIO END ;-) Photo by Unsplash

Slide 25

Slide 25 text

Multi-artifacts support in Microcks @MICROCKSIO #JCONFDEV24 OpenAPI (Primary) Postman Collection (Secondary) Import Import API / Service metadata operations examples examples Test suite others

Slide 26

Slide 26 text

API Lifecycle condensed @MICROCKSIO #JCONFDEV24 API provider API consumer API Mock Write OpenAPI Code API Client Validate against API Mock Test Suite Deploy Application Write Application Get doc & contract Run verification tests (schema + assertions)

Slide 27

Slide 27 text

test strategies @MICROCKSIO #JCONFDEV24 TECHNICAL BUSINESS SMOKE TESTS SYNTACTIC CONTRACT TESTS BUSINESS EXPECTATIONS TESTS Ensure API endpoint is correctly deployed Ensure API implementation is compliant with OpenAPI, AsyncAPI, GraphQL, gRPC or WSDL contracts/schemas Ensure API implementation correctly respond - with respect to business rules - to invocations Different strategies available. Usable on demand, matching your life cycle. POSTMAN STRATEGY SOAP-UI STRATEGY OPEN API SCHEMA STRATEGY ASYNC API SCHEMA STRATEGY GRAPHQL SCHEMA STRATEGY GRPC SCHEMA STRATEGY SOAP STRATEGY HTTP STRATEGY

Slide 28

Slide 28 text

#JCONFDEV24 @MICROCKSIO Demo Time Photo by Unsplash

Slide 29

Slide 29 text

@MICROCKSIO Let’s imagine … 🍰 🎂 🧁 🍩 @MICROCKSIO #JCONFDEV24 Product Domain Pastry API Order Domain Order Service Stores Partners Online Check availability Place orders

Slide 30

Slide 30 text

@MICROCKSIO Order Service Design @MICROCKSIO #JCONFDEV24 Order Service Order Controller / Resource Order Service Pastry API Client REST Endpoint of Pastry API Order API consumers

Slide 31

Slide 31 text

#JCONFDEV24 @MICROCKSIO END ;-) Photo by Unsplash

Slide 32

Slide 32 text

@MICROCKSIO Key Takeaways API CONTRACT-TESTING is a “must mastered” technique to unlock the potential of distributed and decoupled applications Microcks offers a FLEXIBLE MODEL with different testing strategies to make it your own way SCALING CHALLENGES ARE SOLVED with Microcks thanks to a uniform schema-driven approach at the protocol level 1 2 3 #JCONFDEV24

Slide 33

Slide 33 text

@MICROCKSIO #JCONFDEV24 OpenAPI Specification 2.x, 3.x AsyncAPI Specification 2.x Traditional APIs Event-driven Systems CloudEvents Specification 1.0.x Soap WebServices (SoapUI) 5.1+ Postman Collection (JSON) 2.x GraphQL gRPC Services 3.x General Purpose Kafka broker MQTT broker WebSocket server RabbitMQ NATS.io Google Pub/Sub Cover “ALL” kinds of API AWS SQS + SNS

Slide 34

Slide 34 text

@MICROCKSIO Same source-of-truth for inner/outer loops #JCONFDEV24 @MICROCKSIO

Slide 35

Slide 35 text

We need you! Try Microcks (microcks.io)! Follow us on Twitter @microcksio, come chatting on Zulip microcksio.zulipchat.com Distribute & if you like it. Itʼs a 100% Open Source project. And if you love it, contribute! @MICROCKSIO

Slide 36

Slide 36 text

Developer Sandbox! Get free access for renewable 30 days to a self-service, cloud-hosted Kubernetes experience with Developer Sandbox for Red Hat OpenShift. https://developers.redhat.com/developer-sandbox

Slide 37

Slide 37 text

The End