Statement testing is a whitebox, dynamic testing
technique. It requires examination of the source code and the creation
of tests that will exercise individual statements. The project plan
should indicate the proportion of statements that should be tested, this
is usually exprssed as a percentage of "statement coverage".
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 |
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.
For
statement testing, we need to devise a series of tests that will
execute as many statements as are specified in the test plan. If we have
to test all statements then we have to exercise every square box and
every decision in the flowchart.
Test 1
First, we shall run the code with the values: 30 and 20. We expect the output to look like:
a > b
a > 10
a > 10
Using this input data we execute the following statements:
1. Read a // a = 30 2. Read b // a = 30, b = 20 3. IF a > b THEN // True 4. Print "a > b" // "a > b" 5. IF a > 10 THEN // True 6. Print "a > 10" // "a > 10" |
This
test has executed all executable statements except the Print statement
on line 9. This has exercised 6 of the 7 executable statements of the
program, that is 6/7 or 86% statement coverage.
Test 2
To execute the final statement, we shall run the code with the values: 20 and 30. We expect the output to look like:
a <= b
Using this input data we execute the following statements:
1. Read a // a = 30 2. Read b // a = 30, b = 20 3. IF a > b THEN // False 9. Print "a =< b" // "a > b" |
By performing both two tests (Tests 1 and 2) we can execute all statements of the code, achieving 100% statement coverage.
No comments:
Post a Comment