From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Writing integration tests for a web controller

Writing integration tests for a web controller

From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Start my 1-month free trial

Writing integration tests for a web controller

- [Instructor] Let's get started by writing a test for HTTP controller. We will create a new student controller test. We are going to test if we can correctly make a request to students service and get the response we expect. We need to assert certain things about the shape of the response. First, let's create student controller test class. A simple unit test will not cover the HTTP layer so we need to bring Spring Boot to do HTTP magic for us. We could use Spring Boot test but with web MVC test slides Spring fires up an application context that contains only the beans needed for testing a web controller. These beans will evaluate the annotations that would be ignored by simple unit test. We will use mock MVC Spring's MVC test braver to perform HTTP requests on the web in-points inside our mock web environment. Since the mock MVC bean is loaded into the context we will be able to simply auto wire it for our use. We will name our method get student for saved student is returned. As we…

Contents