Support of MockRestServiceServer for WebClient [SPR-15286]
See original GitHub issueStéphane Nicoll opened SPR-15286 and commented
Spring Boot has a @RestClientTest
for pure client-side tests. We currently auto-configure MockRestServiceServer
and bind any RestTemplate
created by the RestTemplateBuilder
to it.
This would be pretty awesome if we could port that feature to WebClient
transparently if webflux is on the classpath. That would require that MockRestServiceServer
can be configured with a WebClient
in addition to a RestTemplate
Sub-tasks:
- #19295 Document how to test WebClient code with a mock server
15 votes, 24 watchers
Issue Analytics
- State:
- Created 7 years ago
- Reactions:26
- Comments:22 (3 by maintainers)
Top Results From Across the Web
Testing Spring WebClient with MockWebServer - mimacom blog
To test *WebClient* code, we need a different setup than for *RestTemplate* based clients. In WebFlux applications the use of the *OkHttp ...
Read more >How to verify/test WebClient usage - spring webflux
I want to test if my code provides the correct headers... shortened sample code: public class MyOperations { private final WebClient webClient; ...
Read more >spring-projects/spring-boot - Gitter
Now I noticed lot guides available online use JSP for web views and I don't find any guide using Gradle and JSP ....
Read more >Mocking a WebClient in Spring - Baeldung
We have two main options for mocking in our tests: Use Mockito to mimic the behavior of WebClient; Use WebClient for real, but...
Read more >mockrestserviceserver,
MockRestServiceServer is a mock server and simple framework for testing ... RestTemplate is a simple Spring class for making REST web service requests....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Using
WebClient
for client-side requests is pretty useless if there is no proper mock in spring for testing our code. Having rewritten myRestTemplate
client code toWebClient
, I’m disappointed there is no replacement forMockRestServiceServer
yet…@membersound I appreciate the point but there is also a lot of effort involved to create, maintain, and evolve something over time and it’s hard to justify given the existing alternatives. HTTP provides loose coupling so implementations can exist and evolve independently. In this case we’re even talking about mocking a server and shaping its behavior. I should think that switching from one to another shouldn’t be as big a deal as it might seem at first. That said MockWebServer has more stars than the Spring Framework does and I don’t think it is going to be a problem with longevity.