WireMock JUnit 5 Extension
What is this?
A JUnit 5 extension for WireMock - the JUnit 5 equivalent of @WireMockRule
.
How to use
Include the dependency in your build:
<dependency>
<groupId>de.mkammerer.wiremock-junit5</groupId>
<artifactId>wiremock-junit5</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
then use WireMockExtension
in your code:
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.net.URI;
import de.mkammerer.wiremock.WireMockExtension;
public class YourTest {
@RegisterExtension
WireMockExtension wireMock = new WireMockExtension();
@Test
void test() {
wireMock.stubFor(
WireMock.get("/hello").willReturn(WireMock.ok("world"))
);
URI uri = wireMock.getBaseUri().resolve("/hello");
// Now make your call against uri, wiremock will answer with "world"
}
}
The extension exposes the same API as WireMockServer
.
See the test as a reference.
Changelog
The changelog can be found here.