Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
MockMvc Kotlin DSL should support async dispatch #23758
Spring MVC now supports returning a Mono from REST controller handler methods. And this, in my experience, becomes more and more common because the reactive WebClient tends to be used instead of RestTemplate in MVC applications.
Testing those handler methods with MockMvc requires doing an async dispatch, as documented here.
This is not easy to find out with the MockMvc Java DSL. But when using MockMvc Kotlin DSL, it's even less intuitive. Here's the required code (AFAIK):
As you can see, it requires:
I can hide this complexity into an extension function, but I think this function shouldn't be required, and should be part of the DSL itself:
This allows using the following code to write the same test as above: