4 ms·
If you find yourself fighting with mocks, ask yourself: is there a deeper design problem with my code? I often find that things I can't test easily have crappy
by michaelmcmillan 7y ago
If you find yourself fighting with mocks, ask yourself: is there a deeper design problem with my code? I often find that things I can't test easily have crappy design.
- theptip 7y agoCouldn't agree more. I've done a few "coding dojo" sessions where my team and I start from scratch and write a new set of mock-based tests for a piece of existing code, and when it starts to get gnarly, it's always been because of an inconsistent interface, or confusing API of the code under test. Bob Martin talks about this a lot; your UTs should be thought of as first-class clients of your objects' APIs. If something is hard to test, it's probably hard to use, or abstracted at the wrong level.