Skip to content

Improve documentation for testing web endpoints with @SpringBootTest and mock #13827

@dsyer

Description

@dsyer

The user guide has a whole section on TestRestTemplate which is great. It doesn't help for a vanilla @SpringBootTest though because the default WebEnvironment is MOCK (I think). My understanding was that WebTestClient was usable wherever MockMvc would have been (i.e the default test environment). But you can't @Autowired one by default.

You have to explicitly @AutoConfigureWebTestClient. There is actually a side bar note about that, but it's quite hard to find, since it is in the section on @WebFluxTest, which I wasn't using.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions