Branch
testing and decision testing are closely related. We will treat them
same. When 100% coverage is concerned, the two techniques are the same.
Branch and decision testing require examination of the source code and the creation of tests that will exercise individual branches of code. A branch is a route from a conditional statement. On a flowchart a branch is a line leaving a decision diamond. For 100% Branch Coverage we should test all branches in a piece of code, we need to achieve all possible results from all of the decision statements.
Branch and decision testing require examination of the source code and the creation of tests that will exercise individual branches of code. A branch is a route from a conditional statement. On a flowchart a branch is a line leaving a decision diamond. For 100% Branch Coverage we should test all branches in a piece of code, we need to achieve all possible results from all of the decision statements.
An Example
Take, as an example, the following source code:
1
2
3
4
5
6
7
8
9
10
| Read a // Executable Read b // Executable IF a > b THEN // Executable Print "a > b" // Executable IF a > 10 THEN // Executable Print "a > 10" // Executable ENDIF ELSE Print "a =< b" // Executable ENDIF |
This is the code we used in Statement Testing
example. The code reads two numbers into variables (a and b). It then
prints out a message indicating which number is the larger. If the
number in variable a is larger than the number in variable b then the
number a is compared to the number 10.
Executable code is indicated in the comments. The ELSE and ENDIF statements are considered to be part of earlier IF statements.
We can represent this code in a flow chart. Every box in the flowchart represents an individual statement.
Executable code is indicated in the comments. The ELSE and ENDIF statements are considered to be part of earlier IF statements.
We can represent this code in a flow chart. Every box in the flowchart represents an individual statement.
Test 1
As before, we shall run the code with the values: 30 and 20. We expect the output to look like:
a > b
a > 10
a > 10
The exercised branches are highlighted in the flowchart below:
This test has exercised two of the four branches in the code, achieving 50% Branch Coverage.
Test 2
For our second test we shall run the code with the values: 20 and 30. We expect the output to look like:
a <= b
This
test exercises one new branch of the code as highlighted in the
following flowchart. We have not yet exercised the N branch from the a
> 10 test.
We have now exercised 3 of the 4 branches, achieving 75% Branch Coverage.
Test 3
To exercise the remaining branch, we shall run the code with the values: 3 and 2. We expect the output to look like:
a > b
The exercised branches are highlighted below.
No comments:
Post a Comment