From @amirensit on Gitter:
Hello In the example of this section of spring boot testing documentation, Is there a missing @AutoConfigureWebTestClientor Am I wrong ?
It looks to me like it is missing. Removing it from WebTestClientSpringBootTestIntegrationTests causes the tests to fail at any rate. I wonder if the subsequent TestRestTemplate example is also missing something.
Comment From: snicoll
It's a bit more complicated than that. @AutoConfigureWebTestClient is required only if the integration test is not running a web server. When it does, both a WebTestClient and TestRestTemplate are contributed, via a ContextCustomizerFactory. So, from that perspective, the annotation there is not required.
Comment From: bclozel
I'm currently looking into #23067 - I'm commenting here first to make sure that I fully understand the current situation and that this new feature will keep things consistent.
Here's my current understanding:
| Annotations on Test class | Server | Web Test Beans configured |
|---|---|---|
@SpringBootTest |
Mock | |
@SpringBootTest @AutoConfigureMockMvc |
Mock | MockMvc, MockMvcWebTestClient* |
@SpringBootTest @AutoConfigureWebTestClient |
Mock | WebTestClient |
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) |
Running | WebTestClient, TestRestTemplate |
With #23067, I'm thinking about adding a MockMvcWebTestClient bean to the context (see second line in the table) if the right dependencies are available. Are we considering here documentation updates only? The situation evolved a lot since the introduction of @SpringBootTest so we can reconsider a few choices still for future versions.
Comment From: snicoll
I am wondering what would be the harm of configuring things in the first case when a web environment is detected? It feels a bit odd that we do it when a RANDOM_PORT or DEFINED_PORT web environment is specified, but not when the default MOCK applies...
Comment From: mbhave
I'm not sure what we need to document here. @AutoconfigureWebTestClient is not required when running with a real server. For the mock case, it is already present in the documentation.
However, I think the documentation for 2.5.x is misleading because this section doesn't seem to clarify that @AutoconfigureWebTestClient is for WebFlux applications only.
Comment From: mhalbritter
2.5.x is out of support and the 2.6.x documentation states that this is for WebFlux. Is there more to do here?
Comment From: bclozel
I think we're good now, thanks for checking @mhalbritter ! I'm closing this as declined since I can't find an issue that really supersedes it.