Getting Started with @WebMvcTest
Get familiar with the utilization of @WebMvcTest using an example.
We'll cover the following...
We'll cover the following...
Create a test
We will begin by making an example @WebMvcTest.
Consider the following UserControllerTest class for the UserController that we have been working with:
-
Annotate the test class with
@WebMvcTestso the testing infrastructure will start. We indicate what controller we want to test by adding the class name of ourUserControllerclass name as an argument to the annotation. -
Spring Test will automatically configure a
MockMvcinstance that we can auto-wire. -
Our
UserControllerhas a dependency of aUserService. Spring Test will not automatically create theUserServiceImplbean, so we either need to create it ourselves or ...