Structural testing criterion example

Example 1

Source code

<source lang="java"> if(a>0){ x=x+1; } if(b==3){ y=0; } </source>


Control flow graph

All-nodes criterion example.svg


Test requirements

All-nodes

All-edges

McCabe

All-nodes criterion example - Path 1.svg All-nodes criterion example - Path 2.svg All-nodes criterion example - Path 3.svg All-nodes criterion example - Path 4.svg

Test cases

  • All-nodes: (a=6, b=3)
  • All-edges: (a=2, b=2), (a=4, b=3)



Example 2

<source lang="java"> if(a>0 && c==1){

  x=x+1;

} if(b==3 || d<0){

  y=0;

} </source>


Test requirements

Structural testing criterion example.svg

  • Statement at line 2 requires both a>0 and c==1 to be TRUE. If the value of a were set to 0 for testing purposes, then the c==1 part of the condition would not be tested (programming language short-circuit).
  • Statement at line 5: requires both b==3 or d<0 to be TRUE.


Multiple conditions

Structural testing criterion example - Multiple conditions 1.svg Structural testing criterion example - Multiple conditions 2.svg Structural testing criterion example - Multiple conditions 3.svg Structural testing criterion example - Multiple conditions 4.svg


Test cases

  • Condition coverage: {a > 0,c = 1,b = 3,d < 0 } and {a <= 0,c 6= 1,b 6= 3, d>= 0}
  • Multiple condition coverage: {a > 0, c = 1, b = 3, d < 0}, {a <= 0,c 6= 1,b 6= 3, d>= 0}, {a>0, c != 1, b != 3, d<0}, and {a <= 0, c !=1, b != 3, d >= 0}

Example 3

Source code

<source lang="java"> if(x && y) {

  conditionedStatement;

} </source>

Test requirements

Test cases

  • Condition coverage: {x=TRUE, y=FALSE} and {x=FALSE, y=TRUE}