4 ms·
Unit testing is supposed to help you design better code. It's a design process that helps you find where you might be tightly coupling things. Are you mocking a
by bphogan 13y ago
Unit testing is supposed to help you design better code. It's a design process that helps you find where you might be tightly coupling things. Are you mocking an external library? Ok, but how? Are you mocking the library directly? Hmmm, maybe you've lashed your code too tightly to that external library. Maybe that means you need some intermediate layer that you do control, so that when Braintree gets bought by Paypal you can change your payment processor by changing the middleware you built.
A unit test tends to expose those tight couplings so that you and your team can decide if you want to keep going down that road or not.
"If it's too hard to test, maybe you should look at the design." Best advice I ever got on TDD.
It's a tool, not a dogma. Use it like a tool to write better code, and get regression tests as a side effect.