What is code coverage?

What is code coverage?

You just pushed your code, it was a new feature and you are proud that your code coverage is 100%. Is it safe to say since the coverage is 100% that you didn’t introduce bugs? I believe you can't.

So what is coverage?

Code coverage gives you an indication on how much lines and/or branches of your code are covered with tests. A code coverage of 70% tells you that 70% of your lines of code are touched and executed with the tests. It therefore also means that 30% isn't tested. Coverage distinguish 4 different aspects:

  1. Statements, are all if-paths taken?
  2. Branches, are all if-else paths taken?
  3. Functions, are all methods called and executed?
  4. Lines, are all line executed?

And what isn't coverage?

Code coverage isn’t a goal. It should be used as a tool to achive a goal; better tests. The coverage doesn’t reflect the code quality, it just tells you how many lines are covered by a test. A piece of code with a coverage of 100% could have as many bugs as code without the tests.

Code coverage barely reflects the quality of code. Of course, when it is well tested the develop spent some time reflecting and refactoring his / her code to be testable, but you can’t conclude that code quality is reflected in code. Business rules could be implemented wrong, or your code has some flaws in one specific browser.

Code coverage barely reflects the quality of tests. It just tells you the coverage of the tests, nothing more. Your test could be false positives and always succeed or your test tests the wrong aspects of your code.

How should I deal with the coverage?

Now you know what code coverage isn’t you probably think, so why should I use it then? Code coverage helps you and your develop team, for example it requires every developer to do minimal effort of testing.

It also helps you to be a better developer. When you write your own code and you know you have to test it you’ll notice that your code will be more clean and easy to understand to make it easier to test.

Read more about:

The bullshit of implementing web accessibility

What is WCAG? Before I dive into the details of web accessibility, let me explain in my own words what it actually is. WCAG stands for Web Content Accessibility Guidelines. It’s a set of guidelines designed to ensure that websites and web applications are accessible to everyone, including people with disabilities…

Continue reading

The bullshit of frontend development

Introduction In this blog, I would like to share my opinion on how we, as front-end developers, often make projects unnecessarily complex. We often think we’re doing the right thing, but are we? Where we used to say we could build a website in just a few days, now we provide timelines at the infamous Scrum…

Continue reading

How I added my Porsche EV to Homekit

Since my childhood, I have been passionate about cars and everything related to them. Even at a young age, I knew every model. I spent hours flipping through car magazines searching for new facts and always dreamed of owning an exotic car. Initially, I used to dream of owning a Ferrari, but as I grew older and wiser,…

Continue reading