Testing
When first written, many programs contain bugs. syntax errorError in a program resulting from code not following syntax rules governing how to write statements in a programming language. are usually quickly removed, but it can take a long time to deduce where a logic errorError in a program which does not cause a program to crash but causes unexpected results. is occurring and why. The purpose of testingAn important part of computer programming which involves checking a program for errors. is to help the programmer remove such bugs and to ensure that the program functions as intended.
Testing requires a test planA plan and record of testing a program that will include the data being tested, its data type, and the expected and actual results of testing.. This is a list of all the tests that the programmer intends to use to ensure the program functions as intended.
Test data
test dataData input when testing to see if the program produces the expected results. 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:
- normal dataSensible, possible data that the program should accept and be able to process. - typical, sensible data that the program should accept and be able to process
- boundary dataValid data that falls at the boundary of any possible ranges. - valid data that falls at the boundary of any possible ranges, sometimes known as extreme data
- invalid (erroneous) data Data that a program cannot process and should not accept. - 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. | Description | Test data | Test type | Expected | Actual |
1 | Test that a possible number is accepted | 5 | Normal | Data is accepted | Data is accepted |
2 | Test the lower boundary | 1 | Boundary | Data is accepted | Data is accepted |
3 | Test the upper boundary | 10 | Boundary | Data is accepted | Data is accepted |
4 | Test that the program does not accept a number less than 1 | -5 | Erroneous | Data is not accepted | Data is not accepted |
5 | Test that the program does not accept a number greater than 10 | 20 | Erroneous | Data is not accepted | Data is not accepted |
Test no. | 1 |
---|---|
Description | Test that a possible number is accepted |
Test data | 5 |
Test type | Normal |
Expected | Data is accepted |
Actual | Data is accepted |
Test no. | 2 |
---|---|
Description | Test the lower boundary |
Test data | 1 |
Test type | Boundary |
Expected | Data is accepted |
Actual | Data is accepted |
Test no. | 3 |
---|---|
Description | Test the upper boundary |
Test data | 10 |
Test type | Boundary |
Expected | Data is accepted |
Actual | Data is accepted |
Test no. | 4 |
---|---|
Description | Test that the program does not accept a number less than 1 |
Test data | -5 |
Test type | Erroneous |
Expected | Data is not accepted |
Actual | Data is not accepted |
Test no. | 5 |
---|---|
Description | Test that the program does not accept a number greater than 10 |
Test data | 20 |
Test type | Erroneous |
Expected | Data is not accepted |
Actual | Data 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.