Spring Boot REST Integration Test with Mockito Java JUnit Tutorial

In this tutorial I show you how to Mock your Spring controller service classes with the new Spring Boot 1.4+ Mockito annotations. I start by taking a test driven development approach. I create a Spring Boot RESTful webservice controller and test it with a @WebMvcTest and MockMvc class. I then expanded the controller to contain a service class. In the junit test, I defined the service class and annotated it with @MockBean. This annotation is used to define a Mockito mock for a bean inside your ApplicationContext. I was then able to use the Mockito BDD behaviour driven development static imports to define what should be returned from the mockito mock object method calls. After The MockMvc test, I verified via mockito static imports that the mock was called once. Don't forget to subscribe for more great tech content! Enjoy! Philip Links: Testing improvements in Spring Boot 1.4: https://spring.io/blog/2016/04/15/tes... Spring Boot Testing: http://docs.spring.io/spring-boot/doc... Junit: http://junit.org/junit4/ Mockito: http://site.mockito.org/ Building REST services with Spring Boot: https://spring.io/guides/tutorials/bo... Spring Boot: https://projects.spring.io/spring-boot/ Mockito BDD / BDDMockito / Behaviour driven development: http://site.mockito.org/mockito/docs/...