Skip to content
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

Change the Documentation in setting up tests to use WebClientTest for Servlet based. #735

Closed
talentedasian opened this issue Jul 5, 2021 · 3 comments

Comments

@talentedasian
Copy link

talentedasian commented Jul 5, 2021

The documentation for setting up tests where you build and bind WebClientTests to application contexts does not specify whether to use MockMvcWebTestClient or WebClientTest. It should specify whether to use (**MockMvcWebTestClient** and **WebClientTest**).bindToApplicationContext for servlet based or projects that use webflux respectively. This cost me so much nuisance and time for a trivial mistake.

@wilkinsona
Copy link
Member

Thanks for the report and sorry for confusion. Unfortunately, it's not clear to me from where the confusion arose. REST Docs does not yet officially support MockMvcWebTestClient (https://github.com/spring-projects/spring-restdocs/issues/691 is tracking that work) and, as far as I can tell, the documentation consistently shows the use of WebTestClient.bindToApplicationContext for building the WebTestClient.

@talentedasian
Copy link
Author

talentedasian commented Jul 5, 2021

The documentation suggested to use WebTestClient but using it causes it to have a noSuchBean named webHandler. I don't know if this is what happens with non-servlets but this only happens I think with servlet based projects. Using the MockMvcWebTestClient class solved my problem and binding it with a WebApplicationContext instead of just an ApplicationContext.

In my opinion the documentation isn't really at fault and it was my ignorance about WebClient but adding clarifications on whether to use MockMvcWebTestClient or WebTestClient if MockMvcWebTestClient gets full support in the future would be a great help :)

@wilkinsona
Copy link
Member

This'll be covered in the documentation updates that are made as part of #691.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants