MockMvcBuilders (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.test.web.servlet.setup

## Class MockMvcBuilders

- java.lang.Object
- - org.springframework.test.web.servlet.setup.MockMvcBuilders

-     public class MockMvcBuilders
      extends Object

  The main class to import to access all available `MockMvcBuilder`s.

  Eclipse users: consider adding this class as a Java editor favorite. To navigate, open the Preferences and type "favorites".

  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MockMvcBuilders()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static StandaloneMockMvcBuilder` | `standaloneSetup(Object... controllers)` Build a `MockMvc` by registering one or more `@Controller`'s instances and configuring Spring MVC infrastructure programmatically.
    `static DefaultMockMvcBuilder<DefaultMockMvcBuilder<?>>` | `webAppContextSetup(WebApplicationContext context)` Build a `MockMvc` using the given, fully initialized, i.e.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MockMvcBuilders

          public MockMvcBuilders()

  - ### Method Detail

    - #### webAppContextSetup

          public static DefaultMockMvcBuilder<DefaultMockMvcBuilder<?>> webAppContextSetup(WebApplicationContext context)

      Build a `MockMvc` 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 a `ServletContext`.

    - #### standaloneSetup

          public static StandaloneMockMvcBuilder standaloneSetup(Object... controllers)

      Build a `MockMvc` by registering one or more `@Controller`'s 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 option is used, the minimum infrastructure required by the `DispatcherServlet` to serve requests with annotated controllers is automatically created, and can be customized, resulting in configuration that is equivalent to what the 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 or the MVC Java config, then using this builder might be a good option for testing a majority of controllers. 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`'s to test