Issue
I am trying to write unit test for the following class
I was wondering if I need to mock the Dependency class
(consider that it is purely logic no DB or external rest calls are made).
I was thinking if I will not mock the Dependency class
, then anyway it will be covered by the CUT
or should I mock it and write separate unit test suite for Dependency class
public interface.
public class ClassUnderTest {
@Autowired
private Dependency dependency;
public Object foo(){
// do something
var = dependeny.bar(args..);
// do somethig
}
}
public class Dependency {
public Object bar(args..){
// do something
}
}
Solution
The main idea of unit testing is to test units separately. Otherwise, it would be an integration test.
In this case, you need to write a separate test suite for Dependency
, and mock the call to it in ClassUnderTest
.
Answered By - amseager