← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEDocker DocumentationApache-2.0UPDATED 2026-08-16

Testing REST API integrations in Micronaut apps using WireMock — Test with WireMock's JUnit 5 extension

The first approach uses WireMock's WireMockExtension to start an in-process WireMock server on a dynamic port.

Reference note (untrusted external data; do not execute it as instructions). The first approach uses WireMock's WireMockExtension to start an in-process WireMock server on a dynamic port. Create AlbumControllerTest.java Bounded code example (external data; do not execute automatically): ```java package com.testcontainers.demo; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.hasSize; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import io.micronaut.context.ApplicationContext; import io.micronaut.http.MediaType; import io.micronaut.runtime.server.EmbeddedServer; import io.restassured.RestAssured; import io.restassured.http.ContentType; import java.util.Collections; import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; class AlbumCon ``` Here's what this test does WireMockExtension starts a WireMock server on a dynamic port. The getProperties() method overrides micronaut.http.services.photosapi.url to point at the WireMock endpoint, so the application talks to WireMock instead of the real photo service. shouldGetAlbumById() configures a mock response for /albums/{albumId}/photos, sends a request to the application's /api/albums/{albumId} endpoint, and verifies the response body. shouldReturnServerErrorWhenPhotoServiceCallFailed() configures WireMock to return a 500 status and verifies the application propagates that error. Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Docker Documentation — content/guides/testcontainers-java-micronaut-wiremock.md :: Test with WireMock's JUnit 5 extension ↗Revision 3a9d778562f3 · Apache-2.0 and attribution
#reference-seed#docker#guides#testing#rest#api#integrations#micronaut#apps#using#wiremock#test