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

The Three Mocketeers and d'AIrtagnan

The Three Mocketeers and d'AIrtagnan

When modeling (aka “mocking”) services during software development, you need to mimic APIs, databases, and other data providers. You can't do this with just one tool; you need to combine several. The good news is that the Testcontainer ecosystem makes it possible to do this with just a few lines of code! And it's available for many ecosystems: Java, Python, JavaScript, Golang, C/C++, .NET, etc.

In this session, I'll demonstrate some ways to create test services, databases, and API providers using Testcontainers and WireMock for a modern Java project, with Gradle and Quarkus. The same approach can be used for other languages, and I'll present examples for Python! Then, we'll extend the approach by adding fake data generation using the Faker or Synthesized libraries, which can be used for both relational and sequence data.

P.S.: And who is d'Artagnan? Prepare for a surprAIse!

Avatar for Oleg Nenashev

Oleg Nenashev

June 17, 2025
Tweet

More Decks by Oleg Nenashev

Other Decks in Technology

Transcript

  1. 2

  2. > whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Developer

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

    - kcd.cloud-native-romandy.ch CFP is Open!
  4. Outline • Intro to API integration testing • Testcontainers and

    WireMock • Using them together • Faking data • Add some AI? :) 9
  5. 13

  6. 14 kotlinlang.org/docs/data-analysis-overview.html Kotlin for Data Science • Kotlin Notebook •

    Kotlin DataFrame • Kandy for visualization • Everything Java has to offer
  7. ◦ Build Scans and Troubleshooting ◦ Local and Distributed build

    caching ◦ Predictive Test Selection ◦ Flaky Tests Detection ◦ Local build observability ◦ // And more! https://gradle.com/develocity/ Apache Maven, Gradle Build Tool, sbt, Bazel + Python + NPM
  8. Most of data comes from APIs • opendata.swiss • kidsfirstdrc.org/portal/portal-about-data

    • vs.inf.ethz.ch/res • github.com/public-apis/public-apis • www.kaggle.com/datasets • data.world 24
  9. Integration Testing 29 • Multiple technology stacks and toolchains •

    Many teams involved • Sacred knowledge • [Almost] always too late
  10. Quarkus Dev Services • Automatic provisioning of unconfigured services in

    development and test mode • Transparent to your application • Mostly containerized, with Testcontainers 33 https://quarkus.io/guides/dev-services
  11. 35 Build Unit tests Publish Reports Integration tests Publish Reports

    NOW “Shift Left” Fast integrations tests are critical
  12. Ways to do integration testing 1. Testing against Production/Staging servers

    2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level 36 Slow Fast Nope Accu- rate
  13. 38

  14. Docker • Popular container engine • Developer-friendly • Huge ecosystem

    • DockerHub and Container Registries • Docker Compose – multi-container apps • Universal image format (OCI) https://www.docker.com/
  15. 41

  16. Testcontainers for Python 44 • Started by Sergey Pirogov, now

    - Till Hoffmann • github.com/testcontainers/testcontainers-python • testcontainers-python.readthedocs.io testcontainers.com
  17. Containers are not always slow! • On-demand image build •

    Caching Docker image builds • Suspending containers between tests • Graceful termination ◦ github.com/testcontainers/moby-ryuk 45 testcontainers.com
  18. 49 wiremock.org IF (request_url) THEN (response) * * it gets

    MUCH more complex WireMock Config JSON: Client library response request Client App Mock API Server HTTP/2
  19. 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
  20. 57 WireMock Standalone client from wiremock.constants import Config from wiremock.client

    import * Config.base_url = 'https://mockserver.example.com/__admin/' mapping = Mapping( priority= 100, request=MappingRequest( method=HttpMethods.GET, url= '/hello' ), response=MappingResponse( status= 200, body= 'hi' ), persistent= False, ) mapping = Mappings.create_mapping(mapping=mapping) all_mappings = Mappings.retrieve_all_mappings() More: github.com/wiremock/python-wiremock Client library response request Test Mock API Server HTTP/2
  21. WireMock as a Proxy 59 Tests Real API Provider OR

    • Recording • Fault injection • Protocol Verification
  22. WireMock Record & Playback wiremock.org/docs/record-playback • Record communications • Capture

    data • Replay the requests • Reverse-engineer protocols to OpenAPI 60
  23. WireMock Faker Extension github.com/wiremock/wiremock-faker-extension • There’re many Data::Faker library ports

    ◦ Python: joke2k/faker ◦ Ruby: faker-ruby/faker (logo source!) ◦ Java: datafaker-net/datafaker • We use the Java one • It can be included in a Testcontainer image 61
  24. WireMock Faker Extension wiremock.org/docs/response-templating/#fake-data-helpers 62 "response": { "status": 200, "jsonBody":

    { "namme": {{random 'Name.first_name'}} "surname": {{random 'Name.last_name'}} "postcode": {{random 'Address.postcode_by_state.AL' }} } }
  25. Synthesized’ Data offerings 64 Synthesized Scientific Data Kit (SDK) Synthesized

    Test Data Kit (TDK) Synthesized Fairlens (Data Bias) www.synthesized.io Data sets / Streams *.CSV Relational datasets (for databases)
  26. 65 Testcontainers Module for Synthesized TDK • Only TDK -

    Relational Data • Only Java Module No Runtime Use at the moment, But NOT a showstopper
  27. 66 TDK SDK Database Module for Testcontainers App Tests WireMock

    Module Build On-Demand Your App Tests • Random Fetch • CSV => JSON generator
  28. When AI in tests? • Non-structured text • Not enough

    test data • Exploratory Testing & Prototyping • Testing GenAI/Model Integrations themselves 71 WHEN ENGINEERS MENTION AI-GENERATED DATA
  29. 72

  30. AI Providers can be modeled, too 74 1. Testcontainers and

    WireMock ◦ OpenAI has an OpenAPI specification ◦ https://github.com/openai/openai-openapi 2. Local Models ◦ Ollama ◦ Langchain4j ◦ Docker Model Runner Recommended
  31. Using Local Models > ollama run qwen3:1.7b > ollama run

    devstral:24b - For Coding > docker model run ai/gemma3-qat:1B-Q4_K_M 75
  32. When to Mock LLM models? • Reproducible Behavior • Fault/Latency

    Injection • Proxying and Recording behavior • Mocking MCP Services 77
  33. Model Context Protocol (MCP) • APIs, but also for your

    Models / AI Pipelines • Based on JSON-RPC 2.0 • Can be and must be tested • Same tools 81 modelcontextprotocol.io
  34. 85

  35. 86 Beware of… • Frameworkitis • Flaky tests • Too

    many tests • Parallelization & resource optimization • Lack of observability * Saw (2004) Yes, that elephant in the room
  36. ◦ Build Scans and Troubleshooting ◦ Local and Distributed build

    caching ◦ Predictive Test Selection ◦ Flaky Tests Detection ◦ Local build observability ◦ // And more! https://gradle.com/develocity/ Apache Maven, Gradle Build Tool, sbt, Bazel + Python + NPM
  37. Takeaways 89 • Shift left your integration testing • Mock

    APIs and Data • There are tools for that, including WireMock and Testcontainers • Model your AI services and LLMs
  38. Choosing a right foundation tool for ITs • Need database

    or complex dynamic environment? ◦ YES => Testcontainers • Do you have a ready implementation? ◦ NO => WireMock/Microcks • Is it containerized and lightweight? ◦ NO => WireMock/Microcks • Can you easily trigger the desired scenarios? ◦ NO => WireMock/Microcks • Else: => Testcontainers 90 * Your mileage may vary ** More later *** I just like footnotes * Likely, you want to use both
  39. Demos from today • github.com/wiremock/wiremock-docker • github.com/wiremock/wiremock-docker/tree/main/samples/random • github.com/oleg-nenashev/gradle-quarkus-plugin-demo •

    github.com/ollama/ollama • github.com/quarkusio/quarkus-workshop-langchain4j • github.com/quarkiverse/quarkus-langchain4j/tree/main/samples 91
  40. Credits to • All WireMock contributors • WireMock Inc. Team

    • All Testcontainers contributors and AtomicJar folks • All FOSS contributors 95