Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

software testing

What is code coverage?

Muhammad Ashir

Code coverage is a measurement of the proportion of code that is executed while automated tests are being run. Code coverage helps in determining the quality of code and investigating how thoroughly a software product has been verified.

A program with a high level of code coverage means there will be a lower probability of finding bugs compared to a program with low code coverage, simply because high code coverage means more of the code has been tested.

The basic criteria for code coverage covers the following aspects:

  1. Statement coverage
  2. Function coverage
  3. Branch coverage
  4. Condition coverage
  5. Edge coverage

Statement coverage

Statement coverage refers to the number of statements or lines that have been successfully executed in the source code.

Function coverage

Function coverage refers to the number of functions and subroutines that are called at least once in the execution of the source code.

Branch coverage

Branch coverage checks whether each branch of every control structure has been successfully executed or not.

Condition coverage

Condition coverage checks if each boolean expression has been successfully executed to provide both true and false results.

Edge coverage

Edge coverage determines if all edges in a control-flow graph have been executed.

Advantages

Code coverage helps in quantitatively assessing the quality of the code and makes it easy to maintain the codebase. More importantly, it helps to identify and expose bad chunks of code that may be error-prone because of inadequate testing. Code coverage is also a good measure of how thorough and reliable the testing suite is; it can also help discover new test cases.

Disadvantages

It is impossible to determine how perfectly the code is covered. Code coverage does not guarantee that all possible test cases or values will be tested.

Tools

There are many open-source and proprietary software available for use in testing code coverage. Some of the more popular tools are:

  1. Cobertura
  2. Clover
  3. Gretel
  4. Kalistick
  5. JaCoCo
  6. JTest
  7. OpenCover
  8. Emma
  9. GCT

RELATED TAGS

software testing

CONTRIBUTOR

Muhammad Ashir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring