Integration testing Spring controllers

In the flows we discussed, we looked at using real unit tests--ones that only load up the specific controllers that are being tested.

Another possibility is to load up the entire Spring context. However, this would be more of an integration test as we would load up the entire context. The following code shows you how to do a complete launch of a Spring context, launching all controllers:

    @RunWith(SpringRunner.class)     @WebAppConfiguration     @ContextConfiguration("file:src/main/webapp/    WEB-INF/user-web-context.xml")     public class BasicControllerSpringConfigurationIT {       private MockMvc mockMvc;       @Autowired       private WebApplicationContext wac;       @Before       public void setup() {         this.mockMvc =   MockMvcBuilders.webAppContextSetup ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.