4 ms·
Mocks make me sad. They are so often misused by people with the best of intentions. I have seen so many tests that literally only assert the mock expectations a
by bhawks 5y ago
Mocks make me sad. They are so often misused by people with the best of intentions. I have seen so many tests that literally only assert the mock expectations and say nothing about the code under test. I have watched upgrades and refactors take 5x longer because someone steps on a landmine of overmocking. It is so common to see people mocking dumb data objects, containers, and pure functions - creating Frankenstein widgets that break all contracts the original had except for the 1 code path the original developer used 6 months ago. I've listened to DRY/SRP fanatics defend mocks until they realized that their tests were littered with unreusable, low fidelity copies of their production system in the form of mocks.
Mocks are a power tool and you can use them to do things that they are not the right tool for the job.
- Aeolun 5y agoIf you correctly use interfaces for your contracts, how can your mocks ever be out of date? Your compilation step would fail.
- bhawks 5y agoContracts cover more than what type systems on most common languages can express. For instance popping a stack with no elements throws an exception. Or similarly constructing an object with certain propertied set cause methods on the object to behave differently. Mocked objects at best encode what the behavior of a certain subset of interactions should be - at a certain point in time.