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

Mocks as code: Modeling AWS service providers w...

Mocks as code: Modeling AWS service providers with Testcontainers, WireMock and Localstack

When managing services at scale, you need automated testing while mocking (or modeling) the parts provided by public clouds, as well as test entire deployment processes. This session demonstrates how to combine Localstack (for AWS integration testing), WireMock (for service mocking), and Testcontainers, a popular framework for Docker and other container engines, for comprehensive integration testing - all running in a Dev Container on your local machine.

Using Pulumi and Java/Gradle as examples, you'll see live coding that shows how these tools work together, though the approach applies to any tech stack. Expect a hands-on workshop format with minimal tool requirements, showcasing developer experience for modern containerized developer environments and practical techniques you can immediately apply to your own services.

Avatar for Oleg Nenashev

Oleg Nenashev

June 26, 2025
Tweet

Resources

More Decks by Oleg Nenashev

Other Decks in Technology

Transcript

  1. Oleg Nenashev Gradle Inc. / CNCF Ambassador Modeling AWS service

    providers with Testcontainers, WireMock and Localstack
  2. 2 Java All the Way Down Up Application Unit Tests

    Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way
  3. Today at 3 Localstack 1. If Needed: Tools Overviews and

    Integration Testing 2. Mocking and Modeling AWS services in integration tests 3. DYI developer environments with Spring Boot Dev Services 4. Infrastructure as Code (IaC) & Pulumi 5. Testing IaC locally & autotests 6. Advanced Troubleshooting
  4. > whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Developer

    Advocate, Gradle Developer Tools Hacker Community Builder #RussiansAgainstPutin #StandWithUkraine
  5. Tell your story at KCD Suisse Romande! 04-05 December 2025

    - kcd.cloud-native-romandy.ch CFP opens on July 1st
  6. 9 Staging & QA Tests Build Integration tests Build Tests

    Gaining confidence in you software “Shift Left” with modern tools
  7. 12

  8. Workshop Prerequisites • Java 21 & your favorite IDE •

    Testcontainers-compatible Docker environment ◦ Tested on: Docker Desktop ◦ You can (try?) use: Podman, Colima, Rancher Desktop (list) ◦ OR: Testcontainers Cloud • Pulumi CLI + registration ◦ Guide: www.pulumi.com/docs/install/ • Nice2Have: Build Scan account ◦ scans.gradle.com/ 14
  9. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides
  10. LocalStack • Local AWS Services emulation OR mocking • “awslocal”

    CLI utility • SDKs for languages and test frameworks 22 docs.localstack.cloud
  11. Some of Them 24 • Emulated: S3, SQS, … •

    Mocked: EC2 (in the FOSS lib) • Thoughts & Prayers: AWS GreenShift ;) • …
  12. Java Example 28 • There is a BOM for Testcontainers

    • Use platforms definitions for it (in Gradle) . . .
  13. 3. Configure the app to use the Mock service 38

    https://github.com/oleg-nenashev/mocks-as-code-demo/blob/main/1_application/src/test/ java/com/testcontainers/demo/MessageListenerTest.java
  14. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides
  15. wiremock.org/docs/stubbing IF (request_url) THEN (response) * * it gets MUCH

    more complex WireMock Config JSON: Client library response request Client App Mock API Server HTTP/2 API Mocking 101
  16. API Mocking Tools Main implementation in Java Native lib, Docker

    images and Testcontainers modules Support for GraalVM Rich Ecosystem Sandbox CNCF Project Golang / Microservice arch Docker image, Testcontainers module, All-in K8s Charts Less Rich Ecosystem
  17. WireMock Ecosystem / Java • Java • Kotlin • Scala

    • Groovy • Clojure • (?)Android 46 • JUnit 4/5 • Testcontainers • Sprint Boot • Spring Cloud Contract • Quarkus • Maven/Gradle • Spock • Pact
  18. 53

  19. Enter -as-Code Tools! • Infrastructure as Real Code • SDKs

    for programming languages • Standard IDEs • Standard Developer Tools • Extensibility via libraries 56
  20. 62 Java All the Way Down Up Application Unit Tests

    Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way
  21. 69

  22. Pulumi for AWS or AWS Native? • AWS Native configuration

    is not applied for endpoints • APIs are slightly different in the package 70
  23. 71

  24. 79 OpenTelemetry plugin for Gradle • Injects traces and spans

    to the Gradle execution • Helps to find the slowest parts of your build with the Gradle OpenTelemetry build plugin. • Created by Craig Atkinson • craigatk/opentelemetry-gradle-plugin
  25. 80

  26. ◦ Build Scans and Troubleshooting ◦ Local and Distributed build

    caching ◦ Predictive Test Selection ◦ Flaky Tests Detection ◦ Local build observability ◦ // And more! gradle.com/develocity Apache Maven, Gradle Build Tool, sbt, Bazel + Python + NPM
  27. • For many open source projects: Gradle sponsors Develocity licenses/hosting,

    helps with build optimization and developer productivity • Maven, Bazel and sbt projects welcome gradle/develocity-oss-projects
  28. 91 Java All the Way Down Up Application Unit Tests

    Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way
  29. Deployment Pipelines and Health Checks • There are tools for

    that, too! • Testcontainers modules for k3s and KIND • You can deploy your CI/CD tools there • Modern Java tools have wrappers, too ◦ E.g. Quarkus - docs.quarkiverse.io/quarkus-helm/dev/example-argocd • Health checks via OTel, AWS CloudWatch or CloudTrail ◦ CloudWatch is a free LocalStack plan, CloudTrail is not 92
  30. 2025: Move to Kotlin? blog.gradle.org/kotlin-dsl-is-now-the-default -for-new-gradle-builds • 2023 - Kotlin

    is a default for Gradle build authoring • Scripts, Plugins, DSL extensions • One language to rule them all?
  31. References • Main Demo: github.com/oleg-nenashev/mocks-as-code-demo • This and other presentations:

    speakerdeck.com/onenashev/ • Build Scan: scans.gradle.com • Develocity: https://gradle.com/develocity/
  32. What I’m looking forward to? • Feedback from Java developers

    • Is Infra-as-Code with Java interesting to you? • Do you want Pulumi-LocalStack for Java productization? • Any other feedback on Gradle :)
  33. Credits 99 • Siva Prasad Reddy and Oleg Shelajev, Docker

    / ex AtomicJar • Nancy Chauhan and Anca Ghenade, ex LocalStack • The demos are based on: ◦ github.com/testcontainers/tc-guide-testing-aws-service-integrations-using-loca lstack ◦ github.com/testcontainers-community/testcontainers-wiremock-demo ◦ github.com/oleg-nenashev/spring_io_2025-Testcontainers-workshop