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.
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-context
module 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...