Affects: 6.1.12
This is not a general how do i do this
question so i hope thats okay here.
What is the recommended way to Mock RestClients in integrationtests?
For WebClient i read that MockWebServer or something similar is recommended (https://docs.spring.io/spring-framework/reference/web/webflux-webclient/client-testing.html). For RestClient there is no such section in the docs (https://docs.spring.io/spring-framework/reference/web/webmvc-test.html)
It states that spring-test provides a MockRestServiceServer that you can use as a mock server for testing client-side code that internally uses the RestTemplate
but in my understanding the RestClient does not use RestTemplate internally or does it?
Should i also use MockWebServer for RestClient or still MockRestServiceServer? Is MockRestServiceServer getting further assistance for RestClient, because in Integration-Tests i cant slice my test and then i also cant use @RestClientTest
.
Comment From: bclozel
@RestClientTest
works for RestTemplate
and RestClient
, as they're both using the same infrastructure. See https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.autoconfigured-rest-client
Comment From: NicoStrecker
@RestClientTest
works forRestTemplate
andRestClient
, as they're both using the same infrastructure. See https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.autoconfigured-rest-client
But then i cant use multiple mockrestseriveservers right?
Comment From: bclozel
Please ask questions on StackOverflow.