Issue
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.
Solution
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 onServiceB
, andServiceB
is not finished yet, you can useMockito
to mockServiceB
just to satisfy your requirements to testServiceA
Hope this answer helps you! you can go to mockito and JUnit5 to learn more about them.
Answered By - ZYinNJU
Answer Checked By - Marilyn (JavaFixing Volunteer)