Assume we wrote a calculation service which provide add and subtract service.
If we would like to do unit test for CalculationService class, and autowire CalculationService into service class as bellows:
As I executed this test class, it returned NullPointerException. This exception result from failed to autowire CalculationService. How to overcome this problem?
We can mock autowired fields by Mockito to solve this problem. Here is the revised test code:
Test result is bellowing: