Course · Training · Workshop

Integration Testing with Testcontainers & WireMock

Two days hands-on: write integration tests against real databases and message brokers in containers, mock HTTP APIs with WireMock and run the same tests on your laptop and in CI.

Integration tests often depend on databases, APIs and other services that are slow to set up, unreliable, expensive or unavailable during development. Testcontainers runs real dependencies in disposable containers that your test code starts and removes. WireMock models HTTP APIs where a real service is impractical to use. Together they give you repeatable integration tests that run from the IDE just like unit tests. In this course you build the integration test suite for an example application in the stack of your team: Java with Spring Boot or Quarkus, Kotlin, Go or Python. You start a PostgreSQL database and a message broker from your test code and check that the migration scripts run against the real database version. You model an external HTTP API with WireMock, exercise successful responses, errors and delays, and verify the requests your application sends. You then combine both tools: WireMock runs in a container as part of the test, and the application is tested against real and mocked dependencies at the same time. With a decision guide you choose for each dependency between a real container and a mock. In the Mocks as Code module you test AWS service integrations locally with LocalStack. For applications that call a language model, you run a small local model in a container and mock the model API to test slow, malformed and nonsensical responses. At the end the same test suite runs on your laptop and in the CI pipeline, with dependencies that are defined as code next to the tests.

What participants say

These customers booked courses in the same topic cluster.More customers →

Content

This training is for software engineers and test automation engineers who want reliable integration tests for services with databases, messaging and external APIs. You work on an example application in your tech stack and extend its test suite step by step.

The course consists of the following topics and can be adapted to the audience. The stack is selected in advance: Java with Spring Boot or Quarkus, Kotlin, Go or Python. For in-house courses we agree on the optional parts and focus areas.

Integration testing fundamentals

  • Classify integration tests and the use cases of the audience
  • Four ways to test API integrations: production or staging servers, containerized instances, mocking at the API provider level and mocking at the code level
  • Decision guide: real dependency in a container or mocked API
  • Hands-On: set up the environment and run the example application

Getting started with Testcontainers

  • Test dependencies as code: start containers from the test and remove them after the run
  • Wait strategies, random host ports and automatic clean-up
  • Testcontainers modules for databases, message brokers and further technologies
  • Hands-On: test the data access layer and the migration scripts against PostgreSQL in a container

Containers for development and more dependencies

  • Add a message broker and connect several containers
  • Testcontainers with Docker Compose and Podman Compose
  • Dev Services for Spring Boot and Quarkus: the same containers for local development
  • Testcontainers in a Dev Container
  • Hands-On: run the application locally with its dependencies in containers

API mocking with WireMock

  • Model HTTP endpoints and configure responses as JSON mappings and in code
  • Exercise successful responses, errors and delays
  • Verify the requests sent by the application
  • Hands-On: mock the external API of the example application and test its client

Combining Testcontainers and WireMock

  • Run WireMock in a container as part of the test with the WireMock module for Testcontainers
  • Test an application against real and mocked dependencies
  • WireMock as a proxy in front of containers or a real system: record and playback, overriding single responses, failure injection
  • Hands-On: write a round-trip test and a test for an API that returns an error

Test data

  • Data modeling and mocking with Testcontainers, WireMock and data libraries
  • Generate fake data for tests
  • Hands-On: provide test data for database and API tests

Mocks as Code for cloud services

  • Test AWS service integrations locally with LocalStack and Testcontainers
  • Combine LocalStack, WireMock and Testcontainers in one test setup
  • Outlook: test Infrastructure as Code locally with Pulumi and the same tools
  • Hands-On: test an AWS service integration against LocalStack

Testing AI integrations

  • Run a small local language model in a container, for example with Ollama
  • Sanity tests against the local model
  • Mock the model API with WireMock for data-driven tests
  • Negative cases: slow responses, nonsensical text and responses that break the expected schema
  • Hands-On: test an AI feature of the example application against a mocked model API

Integration tests in CI/CD

  • Run the same tests in the CI pipeline
  • Container engine requirements in CI
  • Hands-On: run the test suite of the example application in a pipeline

At the end of the two days you have an integration test suite for the example application with real dependencies in containers and mocked APIs. You know how to choose between a real and a mocked dependency and how to bring the setup into your own projects.

The actual course content may differ from the above depending on the trainer, delivery, duration and the composition of participants.

Request this course in-house

By submitting you accept our Privacy Policy.

Request a public date

No suitable public date? Register without obligation — once there is enough interest we schedule a new public date and let you know first.

Number of participants (approx.)

More than 3 participants? Best to request a dedicated in-house date directly.

By submitting you accept our Privacy Policy.

More about Testcontainers and WireMock

Testcontainers is an open source library that provides throwaway, lightweight instances of databases, message brokers or anything else that runs in a container. Test dependencies are defined as code: the library starts the containers before the test, waits with wait strategies until the services are initialized, maps their ports to random free ports on the host and removes all resources after the run. Libraries exist for Java, Go, Python, .NET, Node.js and further languages, with ready-made modules for many technologies.

WireMock is an open source tool for API mocking. A stub defines which response belongs to which request. WireMock returns configured responses, simulates errors and delays, verifies the requests it received and records and plays back traffic as a proxy. The WireMock module for Testcontainers runs the mock server in a container, so real and mocked dependencies are part of the same test setup.

Further resources:

Related courses