Class MockMvcBuilders
MockMvcBuilders
.
Eclipse Users
Consider adding this class as a Java editor favorite. To navigate to this setting, open the Preferences and type "favorites".
- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Sam Brannen
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic RouterFunctionMockMvcBuilder
routerFunctions
(RouterFunction<?>... routerFunctions) Build aMockMvc
instance by registering one or moreRouterFunction
instances and configuring Spring MVC infrastructure programmatically.static StandaloneMockMvcBuilder
standaloneSetup
(Object... controllers) Build aMockMvc
instance by registering one or more@Controller
instances and configuring Spring MVC infrastructure programmatically.static DefaultMockMvcBuilder
webAppContextSetup
(WebApplicationContext context) Build aMockMvc
instance using the given, fully initialized (i.e., refreshed)WebApplicationContext
.
-
Method Details
-
webAppContextSetup
Build aMockMvc
instance using the given, fully initialized (i.e., refreshed)WebApplicationContext
.The
DispatcherServlet
will use the context to discover Spring MVC infrastructure and application controllers in it. The context must have been configured with aServletContext
. -
standaloneSetup
Build aMockMvc
instance by registering one or more@Controller
instances and configuring Spring MVC infrastructure programmatically.This allows full control over the instantiation and initialization of controllers and their dependencies, similar to plain unit tests while also making it possible to test one controller at a time.
When this builder is used, the minimum infrastructure required by the
DispatcherServlet
to serve requests with annotated controllers is created automatically and can be customized, resulting in configuration that is equivalent to what MVC Java configuration provides except using builder-style methods.If the Spring MVC configuration of an application is relatively straight-forward — for example, when using the MVC namespace in XML or MVC Java config — then using this builder might be a good option for testing a majority of controllers. In such cases, a much smaller number of tests can be used to focus on testing and verifying the actual Spring MVC configuration.
- Parameters:
controllers
- one or more@Controller
instances to test (specifiedClass
will be turned into instance)
-
routerFunctions
Build aMockMvc
instance by registering one or moreRouterFunction
instances and configuring Spring MVC infrastructure programmatically.This allows full control over the instantiation and initialization of router functions and their dependencies, similar to plain unit tests while also making it possible to test one router function at a time.
When this builder is used, the minimum infrastructure required by the
DispatcherServlet
to serve requests with router functions is created automatically and can be customized, resulting in configuration that is equivalent to what MVC Java configuration provides except using builder-style methods.- Parameters:
routerFunctions
- one or moreRouterFunction
instances to test- Since:
- 6.2
-