

WireMock Spring Boot Simplifies the WireMock Configuration for Spring Boot Appli...
source link: https://www.infoq.com/news/2023/03/wiremock-spring-boot/?itm_source=infoq&itm_medium=popular_widget&itm_campaign=popular_content_list&itm_content=
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WireMock Spring Boot Simplifies the WireMock Configuration for Spring Boot Applications
Mar 08, 2023 2 min read
WireMock, a flexible tool for building API mocks, and the new WireMock Spring Boot utility simplify the WireMock configuration for JUnit-based integration tests in Spring Boot applications.
Maciej Walkowiak, freelance architect & developer, released the first version of WireMock Spring Boot in February 2023. The project automatically configures the Spring environment properties and provides a fully declarative WireMock setup. Multiple WireMockServer
instances may be used, one per HTTP client. Lastly, this new utility doesn't publish extra beans to the Spring application context, but keeps them in a separate store associated with the application context.
WireMock Spring Boot may be used after adding the following Maven dependency:
<dependency>
<groupId>com.github.maciejwalkowiak.wiremock-spring-boot</groupId>
<artifactId>wiremock-spring-boot</artifactId>
<version>0.1.0</version>
<scope>test</scope>
</dependency>
Currently, the dependency is not yet available on Maven Central, but may be used via the JitPack package repository for Git. JitPack downloads the code from the Git repository after the first request and builds the code to provide the build artifacts, such as JAR files. More information can be found in the JitPack documentation.
The following JitPack repository should be configured in the pom.xml, until the artifact is available in Maven Central:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Tests annotated with @SpringBootTest
, and other annotated tests using the SpringExtension
class, may be annotated with the @EnableWireMock
annotation which enables the WireMockSpringExtension
and adds the test context customizer. The mock is configured with the @ConfigureWireMock
annotation which creates a WireMockServer
and uses the name specified by the property
as the name of an environment property which can be used to retrieve the WireMockServer:
@SpringBootTest
@EnableWireMock({
@ConfigureWireMock(name = "studentservice", property = "studentservice.url")
})
class StudentControllerTest {
@Autowired
private Environment environment;
@WireMock("studentservice")
private WireMockServer wireMockServer;
@Test
void studentTest() {
environment.getProperty("studentservice.url");
wireMockServer.stubFor(get(urlEqualTo("/student"))
…
}
}
The previous example uses the environment.getProperty("studentservice.url")
method to retrieve the URL of the WireMockServer
instance.
WireMock extensions may be configured via the extensions
parameter in the configuration annotation:
@ConfigureWireMock(extensions = { … }, …)
By default, the classpath directory containing the mapping files is set to wiremock/{server-name}/mappings, but may be changed via the stubLocation
parameter in the configuration annotation:
@ConfigureWireMock(stubLocation = "customLocation", …)
Automatically-set Spring properties and the declarative configuration of multiple WireMockServer
instances are advantages of WireMock Spring Boot compared to Spring Cloud Contract WireMock. However, the latter supports contract testing, REST docs and other features.
WireMock Spring Boot uses the concepts and ideas from the Spring Cloud Contract WireMock and Spring Boot WireMock projects and the article Spring Boot Integration Tests With WireMock and JUnit 5. More information about the project can be found on GitHub.
About the Author
Johan Janssen
Architect at ASML, loves to share knowledge mainly around Java. Spoke at conferences such as Devoxx, Oracle Code One, Devnexus, and many more. Assisted conferences by participating in program committees and invented and organized JVMCON. Received the JavaOne Rock Star and Oracle Code One Star awards. Wrote various articles both for digital and printed media. Maintainer of various Java JDK/JRE packages for Chocolatey with around 100 thousand downloads a month.
Show moreRecommend
-
15
TL;DR I released wiremock , a new crate that provides HTTP mocking to test Rust applications. 1use wiremock::{MockServer,...
-
46
``` docker pull holomekc/wiremock-gui ``` WireMock with GUI ====================================================== Extends WireMock with a graphical user interface Key Features ------------ - Mappings - A paginated list of all mapping...
-
11
WireMock - a web service test double for all occasions Key Features HTTP response stubbing, matchable on URL, header and body content patterns Request verification Runs in unit tests, as a standalone p...
-
6
WireMock as a ServiceDecember 5, 2019 · 2 min readWe are pleased to announce that we now have a new mocking service for WebdriverIO called wdio-wiremock-service.What can it do?
-
10
Amplify Framework simplifies configuration for OAuth flows and the hosted UI by Nader Dabit | on 21 JUN 2022 | in
-
13
Visa dives deep into Web3 space by filing crypto and NFT related trademark applications about 8 hours ago
-
8
Supermicro SYS-E302-12E Fanless Industrial PC Review
-
6
WireMock.NET - Troubleshooting 18 April 2023, Author: Cezary Piątek
-
7
flexible, open source API mocking WireMock - flexible API mockingFree and Open Source tool for building mock APIs. Create stable development environments, isolate yourself from flakey 3rd parties and simulate...
-
4
TINA6666 AIQ 938 号成员...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK