White box test design techniques (Part 2)

Path testing

Path testing is considered as a set of structural test design techniques in which test cases are designed to execute every statement and branch in a program at least once. This test technique is mostly used by programmers to unit test their code.

Path testing relies on the control flow of the software under test. This can be represented using a control flow graph.

Control flow graph is the graphical representation of a program’s control structure.

How these control structures have been implemented in a program?

Generally the statements inside a program are  executed from top to bottom, in the order that they appear.

Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching. This  enables your program to conditionally execute particular blocks of code. For example in java programming language, there are

  • Decision-making statements (if-then, if-then-else, switch)
  • Looping statements(for, while, do-while)
  • Branching statements(break, continue, return)

Below presented two sample control flow graphs:

Control Flow Graph

In the above CFG(Control Flow Graph) representation, we could see two components.

They are 1) circles (or nodes) and 2) arrows that join circles (or links).

A circle with more than one arrow leaving called as a decision. 

A decision is a program point at which the control flow can diverge. For example if-then-else, switch etc.

Also a circle with more than one arrow entering is a junction. 

A junction is a point in the program where the control flow can merge.

So far we have discussed the control flow graph and its various components. Now lets focus into the testing. What are the various paths in a program ? Or , What are the criteria for selecting those paths?

A path may go through several junctions, processes(sequence of statements ), or decisions, one or more times. Also has  two specially designated blocks: the entry block, through which control enters into the flow graph, and the exit block, through which all control flow leaves.

 Some cases it has a single entry and a single exit.

However  there are circumstances in which a program may have Multi–Entry/Multi–Exit blocks (examples are given below).

Control Flow Graph Example

Consider the below code segment:
Entry - Exit blocks code example






In the above, we have 4 basic blocks: Block A from 0 to 1, Block B from 2 to 3, Block C at 4 and Block D at 5. Also A is the “entry block”and D the “exit block”.

Path Testing Criteria:

In a typical program, there are numerous paths between entry and exit blocks. Whenever we encounter decision statements in a program, the number of paths gets doubled (i.e. “TRUE” and “FALSE”).

Similar way whenever there is a loop, it multiplies the number of paths by certain iterations. For example in a program a loop supposed to execute 5 iterations. Then the total number of paths multiplies by 5. However each time the code is getting traversed is same, each of those paths are distinct.

There are certain strategies in path testing in order to make sure that the test cases identified should exercise every instructions and branches in a program.

One such strategy is known as Branch Testing

In branch testing, there should be enough test cases to exercise every branch alternative at least once. When we have enough test cases in order to satisfy the above condition, we said to have achieved 100% branch coverage (100% link coverage).

Note that 100% branch coverage usually implies 100% statement coverage too. However the reverse is not true. An example for such scenario explained in the previous blog post.

The main criteria for path selection  is one must pick enough paths to achieve 100% branch and statement coverage in a program.

Also we could make use of couple of path selection rules as listed below

  • Pick the simplest, functionally sensible entry/exit path
  • Pick paths that do not have loops rather than paths that do.
  • Favor short paths over long paths/ simple paths over complicated paths

Nevertheless, this will not cover the bugs related to loops. 

This will be the topic of interest in the upcoming blog post. Stay tuned.


Software Testing Techniques Second Edition by Boris Beizer.

Wikipedia: Control Flow Graph