I use Spring (and Spring Boot, and Spring Data, ...) all the time as well. One of the nice
testing features of Spring is that it includes Mockito as a dependency whenever you make a Spring Boot app, so the framework is already there.
To support Mockito, Spring provides an annotation called
. That tells the framework to create a mock of the annotated class and replace any instance in the application context with that mock. That makes your mock available for dependency injection.
One of the tasks involved when you use Mockito is that you need a way to plug your mocks into the class you're testing. In non-Spring apps, you usually provide a constructor argument or a setter for that purpose. With Spring, dependencies are "autowired" in, so that approach doesn't work. That's why Spring created their own annotation.
You can see an example of this in the Spring Boot documentation in this section:
https://docs.spring.io/spring-boot/docs/3.0.2/reference/htmlsingle/#features.testing.spring-boot-applications.mocking-beans on
Mocking and Spying Beans.
The rest of the concepts in Mockito (what are mocks, stubs, and spies; how do you use them; how do you set expectations, and so on) all work the same way in Spring that they do in non-Spring apps. My book covers those, and while it includes a section on Spring (specifically,
Working with the Spring Framework in the chapter called
Use Mockito in Special Cases), I mostly focus on the general concepts which work the same everywhere.