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 Testcontainers ecosystem lets you 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 show you how to create test services, databases, and API providers using Testcontainers and WireMock for a modern Java project with Gradle and Quarkus. The same approach works for other languages, and I'll show examples in Python! Then, we'll extend the approach by adding fake data generation using the Data 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!

Copyright Notice: Gradle, Inc. Gradle®, Develocity®, Build Scan®, and the Gradlephant logo are registered trademarks of Gradle, Inc. "Gradle" means "Gradle Build Tool" and does not reference Gradle, Inc. and/or its subsidiaries

Oleg Nenashev PRO

June 17, 2025

Transcript

91 slides
  1. 2

  2. DISCLAIMER: • This presentation was modified on Oct 10, 2025,

    to exclude the intellectual property of Gradle Inc. • Most of the informative content is retained • Gradle®, Develocity®, Build Scan®, and the Gradlephant logo are registered trademarks of Gradle, Inc. • "Gradle", if mentioned, means "Gradle Build Tool" and does not reference Gradle, Inc. and/or its subsidiaries. • Other trademarks belong to their respective owners
  3. > whoami Dr. Nenashev / Mr. Jenkins Developer Tools Hacker

    Community Builder Based in Neuchâtel @oleg_nenashev oleg-nenashev #RussiansAgainstPutin #StandWithUkraine
  4. Outline • Intro to API integration testing • Testcontainers and

    WireMock • Using them together • Faking data • And how about d’AIrtagnan? :) 9
  5. 13

  6. Kotlin for Data Science • Kotlin Notebook • Kotlin DataFrame

    • Kandy for visualization • Everything Java has to offer kotlinlang.org/docs/data-analysis-overview.html 14
  7. 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 21
  8. Integration Testing • Multiple technology stacks and toolchains • Many

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

    development and test mode • Transparent to your application • Mostly containerized, with Testcontainers 30 https://quarkus.io/guides/dev-services
  10. NOW Build “Shift Left” Unit tests Fast integrations tests are

    critical Publish Reports Integration tests Publish Reports 32
  11. Ways to do integration testing 1. Testing against Production/Staging servers

    Accurate Slow Nope Fast 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 33
  12. 35

  13. 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/
  14. 38

  15. Testcontainers for Python • Started by Sergey Pirogov, now -

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

    Caching Docker image builds • Suspending containers between tests • Graceful termination ◦ github.com/testcontainers/moby-ryuk testcontainers.com 42
  17. WireMock Config JSON: IF (request_url) THEN (response) * Client library

    request response HTTP/2 Client App Mock API Server * it gets MUCH more complex wiremock.org 46
  18. API Mocking Tools Main implementation in Java Sandbox CNCF Project

    Native lib, Docker images and Testcontainers modules Golang / Microservice arch Support for GraalVM Docker image, Testcontainers module, All-in K8s Charts Rich Ecosystem Less Rich Ecosystem
  19. 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, ) Client library request response HTTP/2 Test Mock API Server mapping = Mappings.create_mapping(mapping=mapping) all_mappings = Mappings.retrieve_all_mappings() More: github.com/wiremock/python-wiremock 54
  20. WireMock as a Proxy Real API Provider OR Tests •

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

    data • Replay the requests • Reverse-engineer protocols to OpenAPI 57
  22. 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 58
  23. WireMock Faker Extension wiremock.org/docs/response-templating/#fake-data-helpers "response": { "status": 200, "jsonBody": {

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

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

    Data • Only Java Module No Runtime Use at the moment, But NOT a showstopper 62
  26. Build On-Demand Your App Tests TDK App Database Module for

    Testcontainers SDK WireMock Module Tests • Random Fetch • CSV => JSON generator 63
  27. When AI in tests? WHEN ENGINEERS MENTION AI-GENERATED DATA •

    Non-structured text • Not enough test data • Exploratory Testing & Prototyping • Testing GenAI/Model Integrations themselves 68
  28. 69

  29. AI Providers can be modeled, too 1. Testcontainers and WireMock

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

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

    Injection • Proxying and Recording behavior • Mocking MCP Services 74
  32. 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 modelcontextprotocol.io 78
  33. 82

  34. Beware of… • Frameworkitis Yes, that elephant in the room

    • Flaky tests • Too many tests • Parallelization & resource optimization • Lack of observability * Saw (2004) 83
  35. Takeaways • Shift left your integration testing • Mock APIs

    and Data • There are tools for that, including WireMock and Testcontainers • Model your AI services and LLMs 85
  36. 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? ◦ 86 NO => WireMock/Microcks • Else: => Testcontainers * Likely, you want to use both * Your mileage may vary ** More later *** I just like footnotes
  37. 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 87
  38. Credits to • All WireMock contributors • WireMock Inc. Team

    • All Testcontainers contributors and exAtomicJar folks • All FOSS contributors 91

More Decks by Oleg Nenashev

Other Decks in Technology