question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support of MockRestServiceServer for WebClient [SPR-15286]

See original GitHub issue

Sté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:closed
  • Created 7 years ago
  • Reactions:26
  • Comments:22 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
membersoundcommented, Jul 24, 2019

Using WebClient for client-side requests is pretty useless if there is no proper mock in spring for testing our code. Having rewritten my RestTemplate client code to WebClient, I’m disappointed there is no replacement for MockRestServiceServer yet…

4reactions
rstoyanchevcommented, Jul 25, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found