Statement Coverage

Each and every software consists of numerous statements. In terms of software programming, a statement is an instruction which is written in the programming language, that tells the computer what action needs to be executed. The main purpose of this article is to help you understand a little bit about a software testing technique known as the Statement Coverage.

Defining Statement Coverage

Statement Coverage is a metric that is used to measure and quantify the total number of statements that have been successfully executed in the source code. This metric is always presented as a percentage. When the coverage is 100%, it means that every statement has been executed once. Sometimes, Statement Coverage is also known as Line Coverage or segment Coverage. It is a white box testing technique whose purpose is to confirm that each statement in the source code is executed at least once.

Mathematical Formula For Statement Coverage

Mathematically, Statement Coverage can be represented by the formula:

Statement Coverage Percentage = (Total no. of statements executed / Total no. of statements) * 100

Pros Of Statement Coverage

The main advantages of Statement Coverage are as mentioned below:

  • Confirms Code Quality – Statement Coverage confirms the quality of the code by ensuring that every statement is executed at least once. It also checks each line of the code to ensure that each statement actually performs the task that it should ideally be performing. If the statement does not execute as per requirement, then it can be fixed to prevent future trouble.
  • Checks The Flow Of Statement – Statement Coverage verifies the flow of the statements. This ensures that each path is tested. It is also helpful in identifying those areas that prevent the execution of the code. Such blocks in the flow can thus be identified and timely action can be taken to correct them.

Cons Of Statement Coverage

The prime disadvantages of Statement Coverage are:

  • Covers True Conditions Only – Statement Coverage is restrictive in nature as it cannot test those conditions that are false. In other words, only true conditions can be tested. This happens because it fails to understand the logic operators. When the role of logic operators comes into play, this metric fails to be completely reliable on its own.
  • Cannot Check If Loop Reaches Termination – Codes tend to consist of loops but Statement Coverage fails to validate if the loop reaches its end point or the point of termination. This happens because Statement Coverage is a very simple metric that fails to go into in-depth paths of the code. It just reads whether the statement was executed or not but does not make any efforts to see if the logical loop end was attained or not.


Statement Coverage identifies those statements in any given method that have been executed. By doing so it is able to recognize those chunks or blocks of code that failed to perform their designated task. Ultimately, identification of these blockages is the main job of Statement Coverage. The higher the Statement Coverage number the better is the quality of the written code. The best part of this testing technique is that it can be conducted by the code developers themselves and that to continuously as each subsequent statement is written.