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

Clarify documentation on use of @AutoConfigureRestDocs with WebTestClient #15977

Closed
jnizet opened this issue Feb 18, 2019 · 3 comments
Closed
Labels
type: documentation A documentation update
Milestone

Comments

@jnizet
Copy link
Contributor

jnizet commented Feb 18, 2019

In Spring Boot 2.1.3, the RestDocsWebTestClientConfiguration class is annotated with @ConditionalOnWebApplication(type = Type.REACTIVE).

This, as far as I understand, prevents the usage of an autoconfigured WebTestClient to document an MVC app, which is strange since you can use WebTestClient to test an MVC app.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 18, 2019
@wilkinsona
Copy link
Member

wilkinsona commented Feb 18, 2019

since you can use WebTestClient to test an MVC app.

My understanding is that you can only use WebTestClient to test an MVC app if you start an embedded server and use HTTP. In other words, using mocked requests and responses is only supported when testing a WebFlux app.

Given a choice between testing an MVC app using MockMvc with no need for a server and using WebTestClient and requiring an embedded container, I would choose the former. I also think that's what we should encourage users to do, hence things being the way they are just now. Perhaps I'm unusual and we should leave the door open to using WebTestClient with HTTP to test an MVC app.

@jnizet Does my understanding of the situation match yours? Is your preference to use WebTestClient over HTTP to test your MVC app?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Feb 18, 2019
@jnizet
Copy link
Contributor Author

jnizet commented Feb 18, 2019

Sure, sorry for the noise.

I'm not very experienced with WebFlux, and missed the WebFluxTest annotation. So I had the feeling that WebTestClient was always used to create integration tests with an embedded server and HTTP, and thus that using MVC or WebFlux wouldn't make a difference.

Now I'm starting to realize that the AutoConfigureRestDocs annotation is usable

  • in a @WebMvcTest-annotated test, to test an MVC controller using a mock MVC context, with the help of au autowired MockMvc
  • in a @WebFluxTest-annotated test, to test a Webflux controller using a mock WebFlux context, with the help of an autowired WebTestClient
  • in a test based on RestAssured, to test an app over HTTP, in order to automatically provide an autowirable documentation spec to the test

WebTestClient can be also be used in @SpringBootTest tests to test an app over HTTP, but then AutoConfigureRestDocs is of no help: the WebTestClient must be configured explicitly, as shown in the Spring REST docs user guide.

To answer your final question: no, my preference is to use sliced tests, using MockMvc, to test and document my MVC apps.
But if I had to write actual integration tests, testing the actual app over HTTP, I guess I would use WebTestClient.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 18, 2019
@wilkinsona wilkinsona changed the title It should be possible to rest-document an MVC app with WebTestClient Clarify documentation on use of @AutoConfigureRestDocs with WebTestClient Feb 19, 2019
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Feb 19, 2019
@wilkinsona wilkinsona added this to the 2.1.x milestone Feb 19, 2019
@wilkinsona
Copy link
Member

Thanks. Let's use this issue to improve the documentation. It sounds like we need to make it clearer when @AutoConfigureRestDocs can be used and when you'd want to configure the WebTestClient yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

4 participants