Testing
When first written, many programs contain bugAn error in a program.. syntax errorError in a program resulting from code not following syntax rules governing how to write statements in a programming language. and runtime errorAn error that takes place during the running of a program. 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. 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
test dataData input when testing to see if the program produces the expected results. is dataUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions. that is used to test whether or not a programSequences of instructions for a computer. 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 inputData which is inserted into a system for processing and/or storage., each designed to prove a program works or to highlight any flaws. Three types of data are:
- normal dataSensible, possible data that the program should accept and be able to process. - sensible, valid 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
- invalid (erroneous) data Data that a program cannot process and should not accept. - invalid data that the program cannot process and should not accept
Test plans
Testing requires a test planA list of what is to be tested and how it is to be tested.. 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 pseudocode Also written as pseudo-code. A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding. 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. | 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 |
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.