How to do it...

Let us perform Spring core testing with JUnit 4, Mockito 2.x, and Spring TestContext framework:

  1. Before we start the configuration, ensure that you have the spring-context module in pom.xml. Then, add the following Spring Test, and now the JUnit 4.x and Mockito 2.x Maven dependencies to your pom.xml:
 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> <exclusions> <exclusion> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.hamcrest</groupId> ...

Get Spring 5.0 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.