Home > Blockchain >  When and where to use JUnit, Mockito and Integration testing in Spring Boot Application?
When and where to use JUnit, Mockito and Integration testing in Spring Boot Application?

Time:11-18

I'm very novice to Unit Testing, I have created a Spring Boot Application and now I want to do some testing what's confusing me is where to use what e.g. I have classes and interfaces Controllers, Service, Repository I know each will have it's own Test class, so what will I be using let's say in Controllers, JUnit or Mockito ? similar question for Service and Repository.

CodePudding user response:

conclusion: JUnit and Mockito can be used at same time, JUnit is used to do common test, and Mockito is used to mock objects.

In my view, JUnit is used more often, and Mockito is only used when I want to mock object, such as the object which is not finished yet. If you just want to test your Controller, Service and Repository, I recommend you to use JUnit. But if you need to mock some objects, you can use Mockito.

For example, when you test ServiceA, which depends on ServiceB, and ServiceB is not finished yet, you can use Mockito to mock ServiceB just to satisfy your requirements to test ServiceA

Hope this answer helps you! you can go to mockito and JUnit5 to learn more about them.

  • Related