4 ms·
Coverage is pretty awesome feedback for reminding you that "oh yeah, I should probably test that case too." And if you start out with this kind of feedback ear
by wyldfire 11y ago
Coverage is pretty awesome feedback for reminding you that "oh yeah, I should probably test that case too." And if you start out with this kind of feedback early it can help influence your design to increase its testability.
If X% coverage is a goal measured by non-technical team members, it likely loses much of its value.
- jerf 11y agoI've been getting into shooting for 100% coverage in critical [1] code lately, and while that may not be to everyone's taste, what I've noticed is that I always learn things from at least looking at the coverage. "Oh, I thought I had that covered... that's interesting, I thought I had that error simulated but it didn't happen after all... oh, look, there's no possible way to ever enter those 125 lines of nasty-looking code plink." Might I also add that I discover errors in the error-handling surprisingly often. Coverage testing goes a long way towards reminding you to check those too. What your code does in error cases is part of the spec. Shooting for 100% may not always be the best use of time, but if you are writing unit tests you should at least look at the line-by-line coverage results. You've already done the hard work of writing the test suite, be sure to reap all the benefits you can. [1]: "critical" is, ahem, a critical word here. I don't shoot for 100% on everything, but every even halfway sanely-designed system has a "core". Total coverage on the core has the dual benefits of assuring the core really does work as intended, and making it possible to refactor the core. It is a very common antipattern for the core to metastasize because without a test suite, all ability to modify it, even to fix bugs, is lost.