To calculate the number of test cases required at minimum for path coverage, you need to cover all paths in the program considering one decision at a time.
Best approach is to draw the flow chart.
Here is an example. Consider the following program code:
$x = 100;
If ($account > 100)
{
for ( $deposit = 1 ; $deposit > 3 ; $deposit ++)
{
$x = $x +1;
}
}
if ($account <= 100)
{
for ($withdraw = 0; $withdraw > 2 ; $withdraw ++)
{
$x = $x -1;
}
}
$x = $x +100;
Now, lets create the control flow graph:
Using McCabe’s technique.
Number of Paths = e – n + 2
e – Edges (lines)
n – Nodes (circles)
Minimal Path coverage: e – n + 2 = 15 – 12 +2 = 5