What is Code Coverage Analysis?

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Code coverage is typically part of the unit testing phase of the software development lifecycle, although it is often used in other testing phases as well. A code coverage tool watches as the suite of unit tests run; then it reports on which functions, branches, loops, and lines of code have and have not been tested. At the highest level, the reports show the percentage coverage for each category; drilling down often shows untested code.

Code coverage analysis tools usually work by instrumenting the code being monitored. Instrumentation adds statements to your code to monitor the code execution. Depending on the source language and the tool, the instrumentation can be via source code injection or executable binary instrumentation.

Test coverage analysis is a supplement to code coverage analysis; it reports whether the test cases cover all of the functional requirements. Because test coverage is qualitative, it is usually a manual process. Test coverage analysis often accompanies test-driven development (TDD).

The Benefits of Code Coverage Analysis

Code coverage analysis exposes untested code. Once you find any untested code, then you have a few options on your team handles the untested code. The team’s response could be to write more tests; to modify existing tests to cover more code branches; or to refactor the code to make it simpler and more testable.

Code coverage analysis provides a metric – percent coverage – that can guide your software QA process. At a high level, repeated code coverage analysis can help your team deliver better products faster, reduce bugs, and simplify QA processes and compliance audits.

Common Tools

The choice of code coverage tools depends strongly on the programming language, operating system, and unit testing framework that your team uses. For example, Visual Studio Enterprise has a code coverage tool integrated with the IDE and has code coverage and unit testing for all its supported languages. It also supports some third-party and open source unit testing frameworks, such as NUnit.

Parasoft produces commercial testing tools for Java, C/C++, and C#. They all include code coverage and unit testing, as well as static analysis and security testing. JetBrains has its own coverage tool for C# called dotCover. This tool integrates with Visual Studio, ReSharper, and the CI environment, TeamCity.

The Go language has its own code coverage tool, integrated with its test tool. If your code is written in Python, you can use Coverage.py, which is open source with an enterprise support option. There are many JavaScript code coverage tools, like Istanbul and Blanket.

This page was originally published on

Your Feedback Is Important

Let us know if this guide was helpful to you.

Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.