> For the complete documentation index, see [llms.txt](https://bernardo.gitbook.io/development-docs-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bernardo.gitbook.io/development-docs-java/testing-spring/testing/preparing-a-controller-for-testing-requests.md).

# Setting Up the MVC Test Context

Notice that the builders generate the MVC context with the build() method.

## Mocking from a Controller

```java
private final UserController getController() {
	final UserService service; // Mocked service

	service = Mockito.mock(UserService.class);

	return new UserController(service);
}
```

```java
mockMvc = MockMvcBuilders.standaloneSetup(getController()).build();
```

## Mocking from Application Context

```java
@Resource
private WebApplicationContext webApplicationContext;
```

```java
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
```
