Skip to content

@SpringBootTest and autowiring MockMvc (#2) #7112

@chrylis

Description

@chrylis

This is a followup to #6008. While the resolution to that added a note to the @WebMvcTest section, the place I as a user was rereading was section 40.3, describing "You can use the webEnvironment attribute". Additionally, the Javadoc for WebEnvironment suggests that the default behavior of @SpringBootTest, with no parameters or extra configuration, is to generate a MockMvc setup if the Servlet API is on the classpath. Adding @WebMvcTest results in a bootstrapper conflict.

From a pragmatic/performance standpoint, not-Web-by-default probably makes sense, but carrying the WebEnvironment on the @SpringBootTest annotation implies that that annotation is sufficient to kick off a Web environment. Since it is not, both the main doc section on @SpringBootTest and the Javadoc should note that, and I'd like to suggest adding a boolean flag to @SpringBootTest to invoke the same effect as adding @AutoConfigureMockMvc or otherwise clarifying the annotation's API to make the additional requirement logically visible from the source.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions