Mockserver Module
Deprecated — use the MockServer-maintained module for new projects
This bundled module is deprecated. For new projects, prefer the MockServer-maintained
module org.mock-server:mockserver-testcontainers
(class org.mockserver.testcontainers.MockServerContainer). It tracks current MockServer
releases, derives its image tag from the client library so the container and client stay in
lockstep, and adds configuration helpers (DNS, transparent proxy, HTTP/3, initialization JSON,
log level, arbitrary properties) plus direct MockServerClient wiring. This page documents the
legacy bundled module.
Mock Server can be used to mock HTTP services by matching requests against user-defined expectations.
Usage example
The following example shows how to start Mockserver.
MockServerContainer mockServer = new MockServerContainer(MOCKSERVER_IMAGE)
And how to set a simple expectation using the Java MockServerClient.
client.when(request().withPath("/hello")).respond(response().withBody(expectedBody));
Adding this module to your project dependencies
Add the following dependency to your pom.xml/build.gradle file:
testImplementation "org.testcontainers:testcontainers-mockserver:2.0.5"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-mockserver</artifactId>
<version>2.0.5</version>
<scope>test</scope>
</dependency>
Additionally, don't forget to add a client dependency org.mock-server:mockserver-client-java
to be able to set expectations, it's not provided by the testcontainers module. Client version should match to the version in a container tag.