Join +2,660 software developers getting weekly tips covering security, quality and system design.
Let's talk about code coverage. When writing tests for your project, it's good to know how much you test. This is where the code coverage metric comes in. It can tell you how many of:
are tested. When your lines coverage is 50%, it means that half of all executable lines of your code is executed during the tests. It means nothing more, nothing less than that. 🛑 It can also be visualised like this below. What coverage should we strive for? 100%? 80%? 50%? Well, code coverage is just... a very good negative indicator!
It's similar to the body temperature. Measuring body temperature is just telling us that something is wrong with our body (low code coverage ❌). You could very quickly lower your body temperature by jumping into the cold water in the bath... 🥶 but will this heal you? Probably not. Similarly, you can increase your code coverage but if your tests are not valuable (just executing the lines of code), it's just like jumping into the cold water to change the indicator. 🙉 To sum up, code coverage is just an indicator. Trying to stick to the high indication, just for the sake of high value, is not that important. What is important though, is writing quality tests and testing the parts of code that are really worth testing. Do you agree? 🙂 Rate this email: Best wishes, |
Join +2,660 software developers getting weekly tips covering security, quality and system design.