White box test design techniques (Part 1)

White box test design techniques : Statement Coverage

White box test design techniques (also known as structural testing, glass box testing ) requires complete knowledge of program source code. These techniques are mostly used by programmers to unit test their own code.

We have already seen the basic difference between white box and black box testing in the blog post “Test case design techniques“.  On these series of blog posts, we are going to discuss the various categories listed under white box techniques.

Statement testing:

Statement testing is a white-box test design technique in which test cases are designed to execute statements.The important questions which comes to our minds are

  • What is a statement?
  • Which statements are executable?      

A statement in programming language is the smallest element which expresses some action to be carried out.

Every statement is either executable or non executable. In general, if a statement specifies an action to take such as performing arithmetic, reading data from an external medium, making a decision, etc, it is executable. Otherwise, it is non executable.

For instance, we would expect all of the following to be regarded as executable:

  •  assignments
  •  loops and selections
  •  procedure and function calls
  •  variable declarations with explicit initialization

Consider the below example:

Read a
Read b
IF a+b > 100 THEN
Print “Sum is large”
IF a > 75 THEN
Print “Input a  is large”

As per statement testing, Execute all the statements in the program at least once under some test.

In order to do this, we need to identify the inputs to this program.

Consider the inputs a = 80 and b = 25.

This input will exercise both the IF statements (i.e  80 + 25 > 100 –> true and  80 > 75 —> true) in the program. 

With this input, we said to have achieved 100% statement coverage . Note that we can achieve 100% statement coverage without testing the “FALSE” condition in the above if statements. Anything less than 100% statement coverage means that not all lines of code executed. Hence this is considered as the weakest criteria. As per ‘ Software Testing Techniques by Boris Beizer (Second Edition) “testing less than this for new software is unconscionable and should be criminalized“.

Statement coverage  generally viewed as the bare minimum.

To calculate statement coverage of a program we can use the following formula:
Statement Coverage = (Number of executable statements executed/Total number of executable statements) * 100 %

Statement coverage is established as a minimum testing requirement in the IEEE unit test standard (ANS187B).