-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Add RestTestClient #34428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add RestTestClient #34428
Conversation
3d73111
to
99c28f0
Compare
99c28f0
to
8cb44e8
Compare
8cb44e8
to
d049e0d
Compare
d049e0d
to
4196fc3
Compare
Fixes spring-projectsgh-31275 Signed-off-by: Rob Worsnop <[email protected]>
4196fc3
to
99afe38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed contribution.
Generally, seems okay on a first pass. Some initial comments on packaging and naming. Let me know if you would you like to continue to iterate over the PR based on my feedback, or if you would prefer me to take over?
I see the symmetry between ~.web.server
package for ~RestTestClient
and ~.web.reactive.server
for WebTestClient
, but ~.web.servlet
is an already established home for server tests with Spring MVC, and having a new package next to that creates an overlap. So, ~.web.servlet
is the "server" package, and this addition can live somewhere undertneath it as a layer over MockMvc alongside others like htmlunit
and assertj
.
It's true that RestTestClient
is for both MockMvc and for live server testing, but the same applies to WebTestClient
as well, which is in one package, and that's fine. It's basically a test client for MockMvc with the extra option to call a live server (anything that implements ClientHttpRequestsFactory
).
We have ~.web.servlet.client
where MockMvcWebTestClient
lives. That package is ideal, and rather than thinking of a new name, we can put RestTestClient
support there as the eventual successor of MockMvcWebTestClient
. In the long run there is no need for both to remain so that should eventually clear up.
This would create a conflict with new and existing AbstractMockMvcServerSpec
and ApplicationContextMockMvcSpec
classes, but it is already confusing to have those IMO, both for MockMvc, but in different packages. Instead if we drop "Mvc" from the name in the new classes, and essentially follow the same convention as in WebTestClient
, i.e. AbstractMockServerSpec
and ApplicationContextSpec
, that would give us two classes with the same name, but one for WebFlux and one for MockMvc, which would be fine.
In short my first suggstion is to move RestTestClient
into .web.servlet.client
, and rename server spec classes accordingly.
In addition I suggest to create a copy of MockMvcClientHttpRequestFactory
in the same package as RestTestClient
, and deprecate the one currently in ~.web.client
. It was added there all the way back in 3.2 because there was no better place at the time, but it has nothing to do with the rest of what's in that package, and makes sense to have it in the same package as RestTestClient
. For anyone currently using that class, this would serve as an alert that there is now higher level support and most likely no need to use that class directly. That could be described in the deprecation notice.
Thanks for the feedback. I will work on this next week. |
Fixes gh-31275