3 ms·
> code is written to be testable first, maybe with lots of mocks If you mean what I think I mean, this is the bottom rung of the ladder. Code that is only test
by stouset 3y ago
> code is written to be testable first, maybe with lots of mocks
If you mean what I think I mean, this is the bottom rung of the ladder. Code that is only testable with lots of mocks is in practice worse than code with no tests.
Tests should do two things: catch undiscovered bugs and enable refactoring. Test mocked to high heaven do one thing: confirm that the code is written the way it’s currently written. This is diametrically opposed to and completely incompatible with those two stated goals. Most importantly, the code can’t be changed without breaking and rewriting tests.
Mocks are okay for modeling owners of external state. Even better are dummy/fake implementations that look and behave like the real thing, (but with highly simplified logic).