Is using mocks in the following way a bad idea:
- writing tests where mocks expect certain calls from the subject under test
- Or even just writing mocks that return values to the subject under test if/when requested
Reason for my doubts: It ties down the SUT to an implementation, since the tests would need to change when the SUT's implementation changes, even if its required behaviour is the same.
I see one alternative: Just pass the SUT the actual collaborating objects it will be working with. So as the implementations change of both, the tests will need fewer changes and still be valid.
Of course there will be times when to thoroughly test an object, it needs to be fed contrived information from the objects it depends on, in which case mocking frameworks might make sense, but still often might be overkill compared to writing test objects that extend an interface common with those collaborators.
Am I missing a benefit of using mocks? Is my above reasoning sound, or should I be using mocks in the above situations for a reason I haven't understood?