ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Software Testing - Statement Testing

Updated on April 27, 2014

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:

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.

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

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 = 20
2. Read b                  // a = 20, b = 30	
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.

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      freaky_ss 4 years ago

      thnksss...used this eg in my report writing

    • profile image

      Flavio Lima 3 years ago

      Sorry, but I got some mistakes on the second test:

      Line 1 comment should be //a = 20

      Line 2 comment should be //a = 20, b = 30

      This would cause on line 3 (a is greater than b) to be FALSE

      Line 9 comment should be // "a is equal or less than b"

      Thank you for the explanation. It was much easier for me to understand with your example.

    • Booster911 profile image
      Author

      Stewart Smith 3 years ago from UK

      Thanks, I've made the correction

    Click to Rate This Article