大象传媒

Testing

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

Test data

is that is used to test whether or not a is functioning correctly. The test data is input, the program is processed and the output is confirmed.

Whenever possible, test data should cover a range of possible and impossible , each designed to prove a program works or to highlight any flaws. Three types of data are:

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

Test plans

Testing requires a . This is a list of all the tests to be used to ensure the program functions as intended. The list should include several examples of normal, boundary and erroneous data.

Tests are laid out in a test plan which might contain:

  • 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:

SET valid TO False
                    WHILE valid = False DO
                         SEND 鈥楨nter a number from 1 to 10鈥 TO 
                         DISPLAY
                         RECEIVE number FROM (INTEGER) KEYBOARD
                         IF number <1 OR number >10 THEN
                            SEND 鈥楴umber outside the range 1 to 10.
                            Enter another number鈥 TO DISPLAY
                         ELSE
                              SET valid TO True
                    END WHILE
                    SEND 鈥楴umber entered is 鈥, number TO DISPLAY

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

Test no.DescriptionTest dataTest typeExpected Actual
1Test that a possible number is accepted5NormalData is acceptedData is accepted
2Test the lower boundary1BoundaryData is acceptedData is accepted
3Test the upper boundary10BoundaryData is acceptedData 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

Test plans should be created before programming starts so that they reflect all the requirements of the program design.

Programmers 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.