Creating tests for Spring MVC components
This first recipe is about writing unit tests for a general Spring 5 web application. This will highlight the basic steps on how to start integration testing with Spring TestContext framework by validating and verifying that all the beans injected into the container are @Autowired correctly in order to build the required MVC application. This framework can be used not only for testing, but also for test-driven development methodology.
Getting ready
Open the previous Maven Spring ch03 and add the following MVC test cases.
How to do it...
Let us perform Spring core testing with JUnit 4, Mockito 2.x, and Spring TestContext framework:
- Before we start the configuration, ensure that you have the
spring-contextmodule inpom.xml. Then, add the following Spring Test, and now the JUnit 4.x and Mockito 2.x Maven dependencies to yourpom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId...