As I understood, Mockito @Mock created a stub with empty methods or methods that otherwise return a default object for each type. On contrary to @Spy which wraps the instance so that you use the actual implementation but still be able to mock certain methods.
However, I have a code such as:
@Mock
private lateinit var context: Context
@Mock
private lateinit var mockConfig: ConfigUtil
And whenever I debug a test I have context
being a Context@MockitoMock
instance, and mockConfig
a real ConfigUtil
instance, therefore, calling any mockConfig
method executes the real ConfigUtil
implementation.
So, does Mockito only stub methods which are not on the build ? (such as Android classes).
--- Q2 ---
Is it a good practice to use @Mock in an object which is meant to test the real method implementation? or only on the dependencies that the instance uses.
In other words, If I create the ConfigUtil
class, and the test suite is for that class, does it make any sense to create a @Mock instance of that class?