This JUnit 5 library for Wiremock provides a way to run a WireMockServer in your JUnit code.
The wiremock library can be added to projects built using gradle or maven as shown below:
Add the dependency to gradle
testImplementation 'io.github.ricall.junit5-wiremock:junit5-wiremock:2.0.0'
Add the dependeny to mvn pom.xml
<dependency>
<groupId>io.github.ricall.junit5-wiremock</groupId>
<artifactId>junit5-wiremock</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
public class TestWireMockLibrary {
@RegisterExtension
public MockServer server = MockServer.withPort(8085);
@Test
public void verifyWiremockWorksAsExpected() {
server.stubFor(get(urlEqualTo("/hello"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello World")));
// You can now query server.url("/hello")
}
}
This software is licensed using MIT