I'm using Spring MVC to develop some controllers.
I would like to write some scenario integration tests which will involve calling multiple controllers of my application.
Normally I would have just used RestTemplate within these tests but the documentation states:
Please, consider using the org.springframework.web.reactive.client.WebClient which has a more modern API and supports sync, async, and streaming scenarios.
And so I would like to write future-proof code by using the WebClient. But I have a number of questions:
- What dependencies should be included here?
// (1) For Spring MVC:
'org.springframework.boot:spring-boot-starter-web:2.4.1'
// (2) For spring webflux
'org.springframework.boot:spring-boot-starter-webflux:2.4.1'
The problem is am I not including too much by having both (1) and (2)? Is there a separate dependency which I should include specifically just to get access to the WebClient? Or is it best practice to include both of these?
- Should I write the tests using the WebClient or TestWebClient?
Given that I just want to make HTTP requests to my server in the integration tests I write - I think using the WebClient is fine? Or is it preferred to use the TestWebClient within these sort of tests? What is best practice?