Home Code Coverage Three top points on code coverage

Three top points on code coverage

Author

Date

Category

Below are descriptions of three top points regarding code coverage including important industry data points so we get a sense of what real companies are doing when it comes to code coverage.
You can also join the discussion on
reddit andย check our ebook: the ultimate guide to code reviews.
We also justย 
released a security dashboardย for your teamย in Codacy.

Best practices dictate that you should trackย code coverage. Code coverage helps you assess the proportion of code that was tested and (more importantly) not tested.

Why is it important to track coverage? Our users report thatย coverageย is important because it is the confidence level of code being correct and with less bugs. Weโ€™ve writtenย previouslyย about code coverage, this is a follow up based on industry data.

In this article we share some evidence of how different companies do code coverage, based on a survey of 680 companies about their code quality practices. Weโ€™ll answer three questions:

  1. Who tracks code coverage? What happens when you donโ€™t?
  2. What thresholds are used for code coverage?
  3. What workflow rules are implemented with code coverage?

Without further adoโ€ฆ

Who tracks code coverage? What happens when youย donโ€™t?

Letโ€™s first look at some of the numbers from our research.

Code coverage breakdown
Code coverage breakdown

Half of the companies track code coverage. Weโ€™ll see in a second how that impacts code quality and other parts of development.

This means that half of the companies cannot trust their code to be without bugs.

The bigger the company the more likely it is to track code coverage, as shown in the chart below.

Coverage tracking by companyย size
Coverage tracking by companyย size

You can see that the larger the company the more likely it is to be tracking code coverage.

Not surprisingly, the older the company the more likely it is to track code coverage too.

Coverage tracking by companyย age
Coverage tracking by companyย age

So the first major question we need to ask is: what is the impact of not tracking coverage?

Here is a quick summary of the impact:

  • 68%ย of peopleย who do not monitor code coverageย feel theyย should have more time to maintain code.
  • 59%ย of those whoย do monitor code coverageย feel theyย should have more time to maintain code.
  • People who monitor code coverageย perceive their code quality to be 7,2% better

Conclusion: although subtle, there are benefits to tracking code coverage.
People who track code coverage feel that the quality of their code is higher, and donโ€™t feel they need to spend more time reviewing code. This the likely reason why more mature companies, which tend to be larger and older, implement code coverage systematically.

Code coverage thresholds?

Code coverage at any given time is really just a number. Itโ€™s the evolution of that number that matters. Code coverage that goes down is an indication that new code is not being tested therefore the confidence level is going down. If itโ€™s going up, normally itโ€™s a good sign.

Minimum code coverage threshold to accept a Pull Request? Most companies donโ€™t

Only 34% of companies require a minimum code coverage threshold to accept a pull request.

What is surprising is the difference between those 34% and 65%.

Here is the real difference between those two groups:

  • Companies that require a minimum code coverage thresholdย perceive their code quality to be 6,4% better.
  • Companies that donโ€™t enforce code coverage thresholds say their biggest problem is technical debt.
  • On the other hand, quality comes at a cost: companies that enforce code coverage thresholds say their biggest problem is speed of delivery.

Another important question is: what is the ideal threshold?

Code coverage popularity
Code coverage popularity

The vast majority of companies that have a code coverage target have set it at 80%. This means the companies that do track code coverage actually set a very high bar with each pull request.

Conclusion: having code coverage thresholdsย increased perceived code qualityย and decreased time spent on tackling technical debt. Companies that required this threshold set the bar, on average, atย 80%.

Code coverage workflowย rules?

Our final consideration is about code coverageย workflow rules.
Do companies require code code coverage to increase whenever new code is introduced? Or do they enforce other rules, for example requiring code coverage not to go down?

First question is: how many companies have code coverage workflow rules?

Less than 20% of companies have rules for code coverage in their workflows.

What are the rules that companies define?

Weโ€™ve asked about four major workflow:

  • Coverage must be same or increase
  • Coverage must increase
  • Coverage must not fall
  • Coverage must pass threshold

Here is the popularity of these rules:

Final thoughts

Code coverage is only as good as the quality of the tests that drive it. Setting a 100% target may tempt developers to game the system by writing unit tests that just increase coverage, at the cost of actually testing the application meaningfully. This is why the majority of the respondents reported a threshold of 80% approx, the most popular workflow rules being โ€œcoverage must not fallโ€ or โ€œcoverage must pass thresholdโ€.

What are your thoughts on these code coverage data points? Let me know!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Recent posts

How does code quality fit into your CI/CD pipeline?

Continuous Integration and Continuous Deployment (CI/CD) are key for organizations wanting to deliver software at scale. CI/CD allows developers to automate...

How Stim uses Codacy to achieve high-quality code

We spoke with Tobias Sjรถsten, Head of Software Engineering at Stim, about how Codacy helps them guarantee code quality and standardization...

6 things developers should do to ship more secure code

Writing better, more secure source code is fundamental to prevent potential exploits and attacks that could undermine your software applications. However,...

Best practices for security code reviews

In today's interconnected world, where data breaches and cyber threats are increasingly common, one of your top priorities should be to...

April Product Update ๐Ÿš€

Hi there ๐Ÿ‘‹ It's been a whirlwind month, and we have big news to share: