Code coverage analysis in software testing

The Blog To Learn Selenium and Test Automation

Code coverage analysis in software testing

Code coverage analysis in software testing.

What is it?
To measure what percentage of code or how many lines of code has been exercised by a test suite.

This can be measured using following formula:

Code coverage = (Number of lines of code exercised)/(Total Number of lines of code) * 100

How it helps?

  • Helps in finding areas of an application that are not exercised by test cases.
  • Test exit criteria can be determined based on code coverage.
  • Information to add additional test cases to increase test coverage can be obtained from code coverage analysis.
  • Redundant test cases that do not increase coverage can be identified and removed.
  • Prevents defect leakage by ensuring all the paths in application are covered.

Things to keep in mind:

  • Code coverage analysis helps to assure the quality of tests, not the quality of the actual product.
  • Not necessarily a good metric of how well testing of product has been carried out.
  • 100% code-coverage only means that every line of code is tested.

Why code coverage analysis alone is not sufficient to measure product quality?

For example, a function that takes x and y returns x/y.

function find(x,y) {
    return x/y;

Problem occurs in application only when y is 0; exception will be thrown in this case, otherwise you would have 100% code coverage.

This analysis should be combined with test design techniques to overcome the cons or disadvantages. Some of the techniques are,

  • Decision table test design technique,
  • Boundary value analysis,
  • Equivalence partitioning,
  • Permutations and Combinations, and
  • Static code analysis etc…

Note: Observation is based on JaCoCo.

Leave a Reply

Your email address will not be published. Required fields are marked *