大象传媒

Testing

When first written, many programs contain bugs. are usually quickly removed, but it can take a long time to deduce where a is occurring and why. The purpose of is to help the programmer remove such bugs and to ensure that the program functions as intended.

Testing requires a . This is a list of all the tests that the programmer intends to use to ensure the program functions as intended.

Test data

is data that is used to test whether or not a program is functioning correctly. Ideally, test data should cover a range of possible and impossible inputs, each designed to prove a program works or to highlight any flaws. Three types of test data are:

  • - typical, sensible data that the program should accept and be able to process
  • - valid data that falls at the boundary of any possible ranges, sometimes known as extreme data
  • - data that the program cannot process and should not accept

Testing tables

Tests are laid out in a testing table, which indicates:

  • the test number
  • a description of what the test intends to check
  • the test data being used
  • the type of test - normal, boundary or erroneous
  • expected outcome
  • actual outcome

Consider this simple program, which asks a user to input a number from 1 to 10:

valid 鈫 FALSE
WHILE valid = FALSE
     OUTPUT "Enter a number from 1 to 10"
     number 鈫 USERINPUT
     IF number < 1 OR number > 10 THEN
          OUTPUT 鈥淣umber outside the range 1 to 10. Enter another number鈥
     ELSE
        聽 valid 鈫 TRUE
     ENDIF
ENDWHILE
OUTPUT ("Number entered is ", number)

This program could be tested using the following normal, boundary and erroneous data.

Test no.DescriptionTest dataTest typeExpectedActual
1Test that a possible number is accepted5NormalData is acceptedData is accepted
2Test the lower boundary1BoundaryData is acceptedData is accepted
3Test the upper boundary10BoundaryData is accepted Data is accepted
4Test that the program does not accept a number less than 1-5ErroneousData is not acceptedData is not accepted
5Test that the program does not accept a number greater than 1020ErroneousData is not acceptedData is not accepted
Test no.1
DescriptionTest that a possible number is accepted
Test data5
Test typeNormal
ExpectedData is accepted
ActualData is accepted
Test no.2
DescriptionTest the lower boundary
Test data1
Test typeBoundary
ExpectedData is accepted
ActualData is accepted
Test no.3
DescriptionTest the upper boundary
Test data10
Test typeBoundary
ExpectedData is accepted
ActualData is accepted
Test no.4
DescriptionTest that the program does not accept a number less than 1
Test data-5
Test typeErroneous
ExpectedData is not accepted
ActualData is not accepted
Test no.5
DescriptionTest that the program does not accept a number greater than 10
Test data20
Test typeErroneous
ExpectedData is not accepted
ActualData is not accepted

Ideally, a programmer should run as many tests as is sensible. Many large programs, especially games, contain bugs simply because it may not be possible to test every possible input or action.