Selecting and using suitable test data
Test data 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. Ideally, 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:
- valid dataSensible, possible data that a program should accept and be able to process. - sensible, possible data that the program should accept and be able to process
- extreme data Valid 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. - data that the program cannot process and should not accept
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 that the programmer intends to use to ensure the program functions as intended. It should include several examples of valid, extreme and invalid data.
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 (valid, extreme or invalid)
- 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 number = int(input("Enter a number from 1 to 10")) if number <1 OR number >10 then print("Number outside the range 1 to 10. Enter another number") else valid = TRUE
endwhile
print("Number entered is ", number)This program could be tested using the following valid, extreme and invalid data:
| Test no | Description | Test data | Test type | Expected | Actual |
| 1 | Test that a possible number is accepted | 5 | Valid | Data is accepted | Data is accepted |
| 2 | Test the lower boundary | 1 | Extreme | Data is accepted | Data is accepted |
| 3 | Test the upper boundary | 10 | Extreme | Data is accepted | Data is accepted |
| 4 | Test that the program does not accept a number less than 1 | -5 | Invalid | Data is not accepted | Data is not accepted |
| 5 | Test that the program does not accept a number greater than 10 | 20 | Invalid | Data is not accepted | Data is not accepted |
| Test no | 1 |
|---|---|
| Description | Test that a possible number is accepted |
| Test data | 5 |
| Test type | Valid |
| Expected | Data is accepted |
| Actual | Data is accepted |
| Test no | 2 |
|---|---|
| Description | Test the lower boundary |
| Test data | 1 |
| Test type | Extreme |
| Expected | Data is accepted |
| Actual | Data is accepted |
| Test no | 3 |
|---|---|
| Description | Test the upper boundary |
| Test data | 10 |
| Test type | Extreme |
| 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 | Invalid |
| 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 | Invalid |
| 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 bugAn error in a program. simply because it may not be possible to test every possible input or action.
Refining algorithms
After an algorithm has been tested, it may need to be refined to improve how it works and to make it efficient. This is a part of the testing life cycle. Refining an algorithm helps to ensure that it is as good as it can be, before being used in a live and active system. Refining an algorithm requires changes that:
- fix problems that are found during testing
- make the algorithm more efficient by reducing any unnecessary or repetitive steps
- improving readability and maintainability so that others can understand the algorithm.