AQA 7517, section 4.13.1.4
Testing is the stage where the implemented program is checked for errors. The aim is to find bugs before the users do, and to show that the program meets its specification.
An important point: testing can show that errors are present, but it can never prove that there are none. That is why test data must be chosen carefully.
Test data
Test data should be selected to cover three kinds of input. Each kind has a different purpose.
| Type of test data | What it is | Purpose |
|---|---|---|
| Normal (typical) | Valid data of the kind expected in everyday use | Check that the program works correctly in ordinary use |
| Boundary | Data at the very edges of what is accepted (and just outside) | Check that limits are handled correctly, where mistakes are most common |
| Erroneous | Data that is invalid and should be rejected | Check that the program copes sensibly, with an error message and no crash |
Other names are accepted for these: typical for normal, extreme for boundary, and invalid for erroneous.
Worked example: designing test data
A program asks for a user's age and accepts a whole number from 13 to 18 inclusive.
| Type | Test value | Expected result |
|---|---|---|
| Normal | 15 | Accepted |
| Normal | 17 | Accepted |
| Boundary (valid, lowest) | 13 | Accepted |
| Boundary (valid, highest) | 18 | Accepted |
| Boundary (just outside, invalid) | 12 | Rejected with a message |
| Boundary (just outside, invalid) | 19 | Rejected with a message |
| Erroneous | 200 | Rejected |
| Erroneous | -4 | Rejected |
| Erroneous (wrong type) | "abc" | Rejected, with no crash |
| Erroneous (wrong type) | 15.5 | Rejected |
| Erroneous (empty) | (nothing entered) | Rejected |
The boundary tests are the most useful. A condition written age > 13 instead of age >= 13 would pass the normal test with 15, but fail the boundary test for 13.
A test plan
Test data is planned before testing, in a test plan (or test table) that records, for each test:
- the purpose of the test;
- the test data to use;
- the expected result (worked out in advance, from the specification, not by running the program);
- the actual result (filled in after the test);
- whether it passed or failed, and any action taken.
| Test | Purpose | Test data | Expected | Actual | Pass? |
|---|---|---|---|---|---|
| 1 | Normal age accepted | 15 | Accepted | Accepted | Yes |
| 2 | Lower boundary | 13 | Accepted | Rejected | No |
| 3 | Below lower boundary | 12 | Rejected | Rejected | Yes |
Test 2 failed, so there's a bug in the lower limit, which needs fixing and re-testing. After any fix, all tests should be run again to make sure nothing else was broken.
The best way to learn this is to design your own test data for your programs, of all three types, and run it: you quickly see which tests find bugs and why.
Levels of testing
Testing is done at several levels as the program is built.
- Unit (module) testing: each subroutine or module is tested on its own.
- Integration testing: the modules are tested together, to check that they work correctly with each other.
- System testing: the whole program is tested against the requirements.
- Acceptance testing: described next.
Acceptance testing
Once the developer's own tests pass, the people who will actually use the system try it out. This is acceptance testing: it checks that the finished system does what the specification promised.
- The users try the system with real tasks, in a realistic setting.
- They check that it does what the requirements said, and that it is usable.
- Their feedback shows whether the system is accepted or needs changes.
- Because the users decide whether it is satisfactory, the test is of whether the system really solves their problem, not only whether it is bug-free.
Why test with the user as well?
A program can pass every technical test and still be unsuitable: awkward to use, or missing something that matters to the users. Developers can be too close to their own work to notice. Acceptance testing finds this out before the system is put into use.
Worked example
Task: a function should accept a password that is 8 to 16 characters long. Give test data of each type with expected results.
| Type | Test data | Expected |
|---|---|---|
| Normal | "sunshine12" (10 characters) | Accepted |
| Boundary | 8 characters | Accepted |
| Boundary | 16 characters | Accepted |
| Boundary (outside) | 7 characters | Rejected |
| Boundary (outside) | 17 characters | Rejected |
| Erroneous | "" (empty) | Rejected |
| Erroneous | a very long string (1000 characters) | Rejected, with no crash |
After the developer's tests pass, a few real users try to set their passwords, and say whether the rules and messages are clear. That's the acceptance test.
Check yourself
Name the three types of test data
Normal (typical), boundary and erroneous.
A program accepts marks from 0 to 100. Give boundary test data
0 and 100 (valid boundaries), and -1 and 101 (just outside, which should be rejected).
What is acceptance testing?
Testing by the intended users of the system, to make sure that the solution meets its specification and their needs.
Why are the expected results worked out before running the tests?
So the actual results can be compared fairly with what the specification says should happen, instead of just accepting whatever the program produces.
Why can testing never prove that a program is error-free?
It is impossible to try every possible input, so errors may remain that the chosen tests did not find.