How to Use WireMock with JUnit 5 in Kotlin Spring Boot Application
Introduction
It is a common practice to use WireMock in our Integration Test to simulate a server response. It allows us to complete our testing, without having to call the actual web endpoint or start a web server, which is awesome!
As of the time of this writing, WireMock does not support JUnit 5. You can see the discussion here. It currently supports JUnit 4’s @Rule
and @ClassRule
to manage its lifecycle automatically.
So, how can we use WireMock in a more seamless way for our Test Classes that use JUnit 5 and have Spring manages its lifecycle?
What You Will Learn
I am going to walkthrough how you can create and register a WireMock Bean and have Spring Application Context manages its lifecycle, just like if you were to use JUnit 4 rules.
Pre-requisite
If you want a complete walkthrough on how to build an application in Kotlin that uses Spring Boot and Spring Webflux along with WireMock for its Integration Test (JUnit 4), check out this article.