I recently had to migrate a project from RestTemplate to WebClient. Unfortunately, unlike for restTemplate, boot does not have any slices setup for testing the WebClient.

I ended up doing something like this

@JsonTest
@ImportAutoConfiguration(
    WebClientAutoConfiguration::class,
    CodecsAutoConfiguration::class,
    ClientHttpConnectorAutoConfiguration::class
)

(That's kotlin, Sorry for not providing a java example) And a lot of manual stuff within the body of the test for managing an okhttp MockWebServer.

It would be really nice if spring boot provided a test slice for this out of the box like it does for RestTemplate.

Also spring framework has a MockRestRequestMatchers class that contains lots of knowledge of the web, far more than a dev like me has. Unfortunately there is no out of the box way to use these with okhttp's RecordedRequests. Can we add some utility functions that convert RecordedRequests into MockClientHttpRequests?

Comment From: snicoll

Thanks for the suggestion but this was covered before. Duplicates of #8404

Comment From: philwebb

We discussed this again today and given this recommendation in the framework docs we think it's worth considering how we might support okhttp mock server in tests.

Comment From: wilkinsona

Duplicates #14223.