Slide 1

Slide 1 text

WORKSHOP: API Integration testing for Spring apps, with Testcontainers and WireMock Oleg Nenashev, Gradle Oleg Šelajev, Docker

Slide 2

Slide 2 text

Async Q&A: Testcontainers and WireMock Slack

Slide 3

Slide 3 text

Demo & Workshop repository ● github.com/oleg-nenashev/ spring_io_2025-Testcontainers-workshop ● Target app: Tracking the TODO list and listing some news for your morning coffee! NOTE: Trademarked names, project and company logos belong to their respective owners 3

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

We will use Gradle Build Tool for the demo this time, Oleg TL;DR: Two Olegs 5

Slide 6

Slide 6 text

Oleg #1 Dr. Nenashev / Mr. Jenkins Community Builder, Gradle Developer Tools Hacker @oleg_nenashev oleg-nenashev #RussiansAgainstPutin #StandWithUkraine

Slide 7

Slide 7 text

Oleg #2 ● ● ● ● Surprisingly, a Java Champion 18+ years software development experience 11 years Developer Advocate Loves to stare at the code of Open Source projects Quarkus Spring Boot LangChain4j Microcks Testcontainers (sometimes contributes bugs too!) linkedin.com/in/shelajev/ youtube.com/user/shelajev/shorts

Slide 8

Slide 8 text

What we talk about today? 1. Spring Dev Services 2. Testcontainers 3. WireMock 4. Everything together 5. Local models for modeling / testing AI 6. Integrations 8

Slide 9

Slide 9 text

About You 9

Slide 10

Slide 10 text

You Have a LOT to Integrate 10

Slide 11

Slide 11 text

When IT Goes wrong 11

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Do you `make it`? IT - Integration Tests 14

Slide 15

Slide 15 text

Today’s lab The workshop! On-demands: ● API Mocking 101 ● Integration Testing 101 ● Testcontainers 101 ● WireMock 101 ● Testing AI applications 15

Slide 16

Slide 16 text

Before We Start ● Level of experience with tech we use ● Do you use Testcontainers? ● Do you use WireMock or Microcks? ● Do you already use Spring Boot Dev Services? 16

Slide 17

Slide 17 text

Want to follow along? ● A Laptop (?) ● Recommended: MacOS / Windows laptops ● Your Favorite IDE ● Docker Desktop 17

Slide 18

Slide 18 text

Before we start ● docker model pull ai/gemma3-qat:1B-Q4_K_M 18

Slide 19

Slide 19 text

101s Integration & API Testing 19

Slide 20

Slide 20 text

Spring Boot and Dev Services

Slide 21

Slide 21 text

See: Presentation by Moritz Halbritter https://www.youtube.com/watch?v=Yqss7tYP890 21

Slide 22

Slide 22 text

Options ● Manual Docker Compose & Co ● Dev Services with Docker Compose ● Dev Service with Testcontainers (!) ○ Test app with ./gradlew bootTestRun https://docs.spring.io/spring-boot/reference/fe atures/dev-services.html 22

Slide 23

Slide 23 text

Integration Testing 101

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Integration Testing ● Multiple technology stacks and toolchains ● Many teams involved ● Sacred knowledge ● [Almost] always too late 25

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

APIs are the Key for Developer Productivity Client App request request response response HTTP/2 API API Server Storage

Slide 29

Slide 29 text

API specs API tech

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

We will develop a custom framework for integration tests Just use xUnit Just use xUnit 31

Slide 32

Slide 32 text

Gaining confidence in you software Build Tests “Shift Left” with modern tools Integration tests Build Staging & QA Tests 32

Slide 33

Slide 33 text

https://martinfowler.com/articles/ mocksArentStubs.html 33

Slide 34

Slide 34 text

Ways to do API integration testing 1. Testing against Production/Staging servers Accurate Slow Nope Fast 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock) 4. Mocking at the code level * For Testcontainers, see the slides

Slide 35

Slide 35 text

Ways to do API integration testing 1. Testing against Production/Staging servers Accurate Slow Nope Fast 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 * For Testcontainers, see the slides

Slide 36

Slide 36 text

Testcontainers 101 36

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Example - Java 38

Slide 39

Slide 39 text

https://testcontainers.com/modules/

Slide 40

Slide 40 text

LOCAL STACK https://testcontainers.com/modules/ 40

Slide 41

Slide 41 text

SDKs testcontainers.org … and 41

Slide 42

Slide 42 text

github.com/testcontainers/ testcontainers-go 42

Slide 43

Slide 43 text

WireMock 101 43

Slide 44

Slide 44 text

No Implementation? Fake it until you “$ make it” 44

Slide 45

Slide 45 text

Ways to do API integration testing 1. Testing against Production/Staging servers Accurate Slow Nope Fast 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 * For Testcontainers, see the slides

Slide 46

Slide 46 text

API Mocking for Java. Examples Open Source Proprietary ` en.wikipedia.org/wiki/Comparison_of_API_simulation_tools

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

API Mocking 101 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/docs/stubbing

Slide 50

Slide 50 text

WireMock Ecosystem & Features wiremock.org/docs

Slide 51

Slide 51 text

WireMock Ecosystem Gradle Build Tool wiremock.org/docs

Slide 52

Slide 52 text

WireMock in Java wiremock.org/docs/stubbing

Slide 53

Slide 53 text

WireMock Ecosystem / Java ● Java ● Kotlin ● Scala ● Groovy ● Clojure ● (?)Android ● ● ● ● ● ● ● ● JUnit 4/5 Testcontainers Sprint Boot Spring Cloud Contract Quarkus Maven / Gradle Build Tool Spock Pact 53

Slide 54

Slide 54 text

Example - JUnit 5 54

Slide 55

Slide 55 text

WireMock Plugin for Gradle Build Tool William-Hill-Online/wiremock-gradle-plugin Gradle Build Tool 55

Slide 56

Slide 56 text

WireMock for Spring Boot ● There is a library for it! ● https://wiremock.org/docs/solutions/ spring-boot-integration/ 56

Slide 57

Slide 57 text

WireMock has an official Testcontainers module! testcontainers.com/modules/wiremock 57

Slide 58

Slide 58 text

Demos ● https://github.com/wiremock/wiremock-docker ● https://github.com/oleg-nenashev/mocks-as-code-demo ● https://github.com/wiremock/wiremock-grpc-demos ● https://github.com/wiremock/wiremock-spring-boot-oauth2-demo 58

Slide 59

Slide 59 text

WireMock or Testcontainers?

Slide 60

Slide 60 text

Choosing a right tool * ● 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 * Likely, you want to use both * Your mileage may vary ** More later *** I just like footnotes 60

Slide 61

Slide 61 text

61

Slide 62

Slide 62 text

WireMock has an official Testcontainers module! testcontainers.com/modules/wiremock 62

Slide 63

Slide 63 text

Proxy can be made transparent in your test! Tests 63

Slide 64

Slide 64 text

WireMock Proxy? Why? ● Record & Playback for Request sequences ● Reverse engineering of legacy undocumented APIs ● NEW: OpenAPI Standard Compliance Verification (in 3.0 Beta) ● Emulating complex cases ○ Overriding particular responses ○ Emulating response sequences / Stateful behavior ○ Failure Injection 64

Slide 65

Slide 65 text

More Demos ● Simple WireMock and Testcontainers demo: github.com/testcontainers-community/testcontainers-wiremock-demo ● WireMock and Docker integration tests: https://github.com/wiremock/wiremock-docker ● Quarkus Dev Service for WireMock and Testcontainers: https://github.com/oleg-nenashev/gradle-quarkus-plugin-demo ● Spring Boot + Testcontainers and WireMock + LocalStack: https://github.com/oleg-nenashev/mocks-as-code-demo

Slide 66

Slide 66 text

Docker Model Runner 66

Slide 67

Slide 67 text

Docker Model Runner ➔ Run models locally with full GPU support ➔ Distribute models through container registries ➔ Easily integrate using any OpenAI-compatible SDKs and libraries compose.yaml services: llm: provider: type: model options: model: ai/gemma3:4B-F16 app:

Slide 68

Slide 68 text

Resources ● Docker Model Runner docs: https://docs.docker.com/model-runner/ ● Using Docker Model in Docker Compose https://docs.docker.com/compose/how-tos/model-runner/#provider-services ● Using Docker Model Runner for AI assistant setup: https://dev.to/olegshelajev/easy-private-ai-assistant-with-goose-and-docker-model-runner-4b41

Slide 69

Slide 69 text

Lessons Learned 69

Slide 70

Slide 70 text

Takeaways ● Shift left the integration testing ● API Mocking / abstraction are great… when used right ● There is no silver bullet ● WireMock and Testcontainers address their own use-cases ● They work well together! 70

Slide 71

Slide 71 text

Choosing a right tool * ● 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 * Likely, you want to use both * Your mileage may vary ** More later *** I just like footnotes 71

Slide 72

Slide 72 text

Keep Learning Tools * AKA: Burning Out 101 72

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

It’s [always] a great time to contribute! testcontainers.org/contributing wiremock.org/participate 74

Slide 75

Slide 75 text

Questions? Testcontainers Slack WireMock Slack 75