Skip to content

0.1.0

Compare
Choose a tag to compare
@maciejwalkowiak maciejwalkowiak released this 27 Feb 16:38
· 42 commits to main since this release

WireMock Spring Boot library drastically simplifies WireMock configuration in a Spring Boot and JUnit 5 application.

🤩 Highlights

  • fully declarative WireMock setup
  • support for multiple WireMockServer instances - one per HTTP client as recommended in the WireMock documentation
  • automatically sets Spring environment properties
  • does not pollute Spring application context with extra beans
  • configuring WireMock extensions via @ConfigureWireMock(extensions = ... )
  • configuring stub locations via @ConfigureWireMock(stubLocations = ... )

✨ How to use

Use @EnableWireMock with @ConfigureWireMock with tests annotated that use SpringExtension, like @SpringBootTest:

@SpringBootTest
@EnableWireMock({
        @ConfigureWireMock(name = "user-service", property = "user-client.url")
})
class TodoControllerTests {

    @WireMock("user-service")
    private WireMockServer wiremock;
    
    @Autowired
    private Environment env;

    @Test
    void aTest() {
        env.getProperty("user-client.url"); // returns a URL to WireMockServer instance
        wiremock.stubFor(...);
    }
}
  • @EnableWireMock adds test context customizer and enables WireMockSpringExtension
  • @ConfigureWireMock creates a WireMockServer and passes the WireMockServer#baseUrl to a Spring environment property with a name given by property.
  • @WireMock injects WireMockServer instance to a test

📢 Feedback is much appreciated!

If you find this library useful, consider ❤️ Sponsoring the project! Thank you!