Spring Unit Testing with Mockito
Explore how to write unit tests in Spring using the Mockito framework. Understand how to mock dependencies effectively to isolate the class under test, improving test speed and reliability. This lesson guides you through adding Mockito dependencies, mocking interfaces, and best practices for testing in Spring without loading the full application context.
We'll cover the following...
The RecommenderImplementation class has a dependency on the Filter interface. Ideally, when writing unit tests, we should only focus on the class under test and mock the dependencies instead of initializing the dependency. We will now write a test for the same class using Mockito.
mockito-core dependency
To test using the Mockito framework, we need the mockito-core dependency, which can be added to pom.xml as follows:
Note: The above dependency is automatically available if ...