From the course: Creating Spring Boot Microservices
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
JUnit, Mockito, and SpringBootTest - Spring Boot Tutorial
From the course: Creating Spring Boot Microservices
JUnit, Mockito, and SpringBootTest
- [Instructor] So now we have some other comments from other developers on our team, and one is on TourRatingService. "This class needs some JUnit test coverage. Mock these calls to the repository method." Great comment. The next one is on the TourRatingController. "Please add @SpringBootTest JUnit test." I couldn't agree more. I really feel guilty when I write code and I don't have any unit tests on it. And so the goal of these unit tests, I have in front of me, the TourRatingService test. And so this is to test the Tour Rating Service, all of the public methods within the TourRatingService and underneath the TourRatingService, invokes the Tour repository and the Tour rating repository. So we don't want to invoke those. We want to just test the code within the TourRatingService. So how we do that is we mock and we're using a tool called mockito, and we annotate our class, TourRatingService test. These are within the test source folder. And so we say okay, it extends the mockito…