by davedx · 5y ago · 0 comments
I disagree strongly with “90%+ unit test coverage” though. Diminishing returns are very real there.
Hi, stupid junior here. Can you elaborate a bit or give me some reading material? I'm currently struggling to get good practices with tests and understanding associated metrics. Thank you!
https://testing.googleblog.com/2010/07/code-coverage-goal-80...
That said, it's very easy to write tests that produce high code coverage, but do not test much that is useful (do they assert the things we truly need to check for?). It's also a pointless exercise to try and cover every single branch (e.g. does every defensive error check need to be asserted on?)
It's a delicate balance and I'm sure some people will disagree with this, even.
Parent post is right that lower coverage degrades rapidly... the difference between 65% and 75% is huge. But the ancestor post is right that there’s large diminishing returns too.
I’ll qualify this with recommending leaning hard into lints and type checkers and the like. Eliminating whole classes of errors gives the edge; rather than writing test cases in, say, Python to ensure that a string-mangling function raises the “correct” exception if passed an int… just enforce mypy checking instead. And then get your type coverage up to 75-80 percent. Fuzzers too. Get more overall coverage by letting the computer do the work.
When I can't, I ponder.
I see how my design can be aided by coverage and ask "Hey, I don't have coverage for this, why did I write it?"
It's a worthwhile question. I wrote code, but it is hard to exercise easily... why did I write it?
Don't get me wrong, there is a bunch of stupid shit to contend with (I'm looking at you MessageDigest AlgorithmNotFound)
I’ve seen enough 100% or close to completely broken applications.
Major business rules need tests too, but they are much harder to write - so we get high unit test coverage and not hard conversations about test quality.
>able to change logging level without code changes
The folks at Suckless would like a word. ;-)
Personally, I think having to recompile software just to change settings is a royal pain in the butt.