From the course: Test-Driven Development in Spring Boot with JUnit and Mockito

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Working with MockMvc

Working with MockMvc

- [Instructor] All right, now that we've implemented the service layer using test-driven development, it's time to move on to the final layer of our application, the controller layer. And for this, we'll be using Spring's MockMvc. The controller layer is where our application interfaces with the outside world. The controller handles HTTP requests and returns responses. We'll be creating restful endpoints for a task management API. To test the controller layer, we'll use MockMvc. MockMvc is a powerful tool provided by Spring for testing Mvc applications. As the name predicts, there's simulation going on again. MockMvc allows us to simulate HTTP request and assert responses without actually starting a web server. This means our tests are focused on the controller's behavior and they're also, as a bonus, extra fast. I have a question for you. How do we test the controller in isolation when it depends on the service layer? I hope your remember this from the previous module. Just like we…

Contents