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

Revolutionizing API Testing and Mocking with Te...

Revolutionizing API Testing and Mocking with TestContainers Modules | jConf.dev 2024

In Hugo Guerrero's session at jconf.dev, he emphasized how Microcks and Testcontainers streamline API and microservices testing. While Testcontainers has become essential for integration testing with databases and middleware, Microcks extends this simplicity to API mocking and testing without requiring extensive setup. As a CNCF Sandbox project, Microcks allows developers to shift left by creating testing environments early in the development cycle, handling various API types like REST, gRPC, GraphQL, and Async across different tech stacks. Together, these tools eliminate uncertainty, making integration testing much more manageable.

Hugo Guerrero

September 26, 2024
Tweet

More Decks by Hugo Guerrero

Other Decks in Programming

Transcript

  1. @MICROCKSIO Hugo Guerrero Mexican @ MA, USA @hguerreroo Event-Driven APIs

    Specialist Open Source Advocate History, Travel & Food Enthusiast #JCONFDEV24
  2. @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.
  3. @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
  4. @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
  5. @MICROCKSIO #JCONFDEV24 @MICROCKSIO Docker/AtomicJar partners with so ware vendors to

    maintain and certify official modules. Java, NodeJS, Go, …
  6. @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
  7. @MICROCKSIO @MICROCKSIO #JCONFDEV24 turns your artifacts into mocks in seconds

    INGEST PROVIDE MOCKS WELL-KNOWN ARTIFACTS SMART MOCKS API Consumer and others
  8. @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
  9. @MICROCKSIO Microcks Testcontainers Java #JCONFDEV24 Java library for Testcontainers that

    enables embedding Microcks into your JUnit tests with lightweight, throwaway instance thanks to containers
  10. @MICROCKSIO Microcks Quarkus Extension #JCONFDEV24 Quarkus extension that enables embedding

    Microcks as a DevService managing mocks for dependencies and contract-testing your API endpoints
  11. 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
  12. @MICROCKSIO Let’s imagine … 🍰 🎂 🧁 🍩 @MICROCKSIO #JCONFDEV24

    Product Domain Pastry API Order Domain Order Service Stores Partners Online Retrieve Place orders
  13. Multi-artifacts support in Microcks @MICROCKSIO #JCONFDEV24 OpenAPI (Primary) Postman Collection

    (Secondary) Import Import API / Service metadata operations examples examples Test suite others
  14. 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)
  15. 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
  16. @MICROCKSIO Let’s imagine … 🍰 🎂 🧁 🍩 @MICROCKSIO #JCONFDEV24

    Product Domain Pastry API Order Domain Order Service Stores Partners Online Check availability Place orders
  17. @MICROCKSIO Order Service Design @MICROCKSIO #JCONFDEV24 Order Service Order Controller

    / Resource Order Service Pastry API Client REST Endpoint of Pastry API Order API consumers
  18. @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
  19. @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
  20. 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
  21. 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