Using mocks to set up object even if you will not be mocking any behavior or verifying any interaction with it?
- by smp7d
When building a unit test, is it appropriate to use a mocking tool to assist you in setting up an object even if you will not be mocking any behavior or verifying any interaction with that object?
Here is a simple example in pseudo-code:
//an object we actually want to mock
Object someMockedObject = Mock(Object.class);
EqualityChecker checker = new EqualityChecker(someMockedObject);
//an object we are mocking only to avoid figuring out how to instantiate or
//tying ourselves to some constructor that may be removed in the future
ComplicatedObject someObjectThatIsHardToInstantiate = Mock(ComplicatedObject.class);
//set the expectation on the mock
When(someMockedObject).equals(someObjectThatIsHardToInstantiate).return(false);
Assert(equalityChecker.check(someObjectThatIsHardToInstantiate)).isFalse();
//verify that the mock was interacted with properly
Verify(someMockedObject).equals(someObjectThatIsHardToInstantiate).oneTime();
Is it appropriate to mock ComplicatedObject in this scenario?