5 ms·
Ask HN: What is your ideal code coverage in terms of percentage?
Do you think it should be a 100%? 50%? 75%?
Share what you think and why!
- mikeluby 9y agoTo me, it's less about a specific number and more about ensuring all core logic is covered. You can hit your coverage goals by by testing getters/setters for example, but that doesn't mean that your coverage is effective. Having core business logic covered will give you the confidence in fixing, refactoring, updating those key pieces of the application.
- taylodl 9y agoAnecdotally speaking, by the time you've tested the prevalent happy paths and unhappy paths, you will have covered roughly 70% of your code. So a code base having less than 70% coverage would be a "smell" to me in terms of adequate testing. The remaining code will be tested as-needed using Maintenance Driven Development - see https://taylodl.wordpress.com/2012/07/21/maintenance-driven-development/ https://taylodl.wordpress.com/2012/07/21/maintenance-driven-...
- davismwfl 9y agoDepends on the type of code and what it is. e.g. an embedded device should likely have better code coverage than say a CRUD application on the web. Even on an embedded device though, it is typically less than 100%, unless the device is safety critical. Personally in order of most to least code coverage as my own general rule: Safety critical code, embedded device, mobile application, desktop application than web application. Not because web isn't important, but it is far easier and cost effective to address issues. I'd say the code coverage percentage (if you will) goes hand in hand with a few factors, criticality of the code, sophistication of the team and the business risk of errors (even from a marketing perspective). I've worked on safety critical devices that should have had 100% code coverage that didn't, and worked on web based marketing apps where 100% code coverage was mandated because we lost money and customer confidence if any piece failed. Personally I have seen a pattern with the more senior the team makeup, it seems like the less total code coverage but the testing is more thorough and targeted. I honestly think this goes more based on trust within the team then just pure time behind the keyboard. I have also seen it bite teams too, so not sure it is the "smart" choice.