3 ms·
I think unit tests are a great tool to motivate code that is simple and easy to reason about. After all, a good unit test is itself simple and easy to reason ab
by entee 10y ago
I think unit tests are a great tool to motivate code that is simple and easy to reason about. After all, a good unit test is itself simple and easy to reason about. It also forces you to think about what is the simplest unit of software for a given task, helping design the software it is testing.
Also, I've definitely had code I thought was well tested and good to go, but when I rigorously went back and wrote unit tests, I found subtle bugs I wouldn't otherwise have known to fix.
That said, yeah it's not all it takes to get things right. Dogma is bad, but unit tests are an essential part of the toolkit for ensuring code quality.
- kedean 10y agoYeah, i've found that my heavily unit tested code is often my best code, simply because designing it with that in mind yields the simplest, smallest units. If I know I'm gonna need to write a unit test later, I'm much more inclined to split a long function out into more sensible small ones, and I'm not going to try to combine two different behaviors (because that's hell to test).