UNIT 2 • MODULE 2 • LESSON 08
The library program from Lesson 07 compiles and produces sensible output. Is it finished? Not yet. A program that runs is not the same as a program that is right. The validation phase checks two things: that the software does what the specification says, and that it actually meets the needs of the people who will use it. This lesson covers why testing matters, how to plan it, the different levels and kinds of testing, and the two main ways to design test cases: black-box and white-box.
You already wrote test plans and trace tables in Unit 1 • Module 2 • Lesson 09 – Tracing Algorithms: Trace Tables, Test Plans and Correctness and tested C programs in Unit 1 • Module 3 • Lesson 10 – Testing, Debugging and Good Style in C. Here those skills are placed inside the life cycle and scaled up to a whole system.
What you will learn
- Why testing is needed, and the difference between verification and validation.
- What a test plan contains.
- Software inspection (static checking) versus software testing (running the code).
- Unit (component), integration and system testing.
- User testing: alpha, beta and acceptance testing.
- Black-box testing with normal, boundary and erroneous data.
- White-box testing based on the paths through the code.
- Running a set of test cases automatically in C.
Part 1: Why test?
Every non-trivial program contains faults when it is first written. Testing finds as many as possible before users do. The cost of fixing a fault rises sharply the later it is found: a fault caught by a programmer during unit testing may take minutes to fix, while the same fault discovered after release may need an emergency update, data repairs and an apology to customers. Testing also builds confidence that the system is ready, and it provides evidence for the customer that the requirements have been met.
| Verification | Validation | |
| Question | “Are we building the product right?” | “Are we building the right product?” |
| Checks against | The specification and design | The users’ real needs |
| Examples | Inspections, unit and integration tests | System and acceptance testing, beta testing |
Remember too that testing can show the presence of faults, but it cannot prove that there are none. That is why test cases must be chosen carefully, to find as many faults as possible with a reasonable number of tests.
Part 2: Test plans
A test plan is a document, written before testing starts, that sets out what will be tested, how, by whom and when. A typical test plan includes:
- The items and features to be tested (and any not being tested).
- The approach: levels of testing and the techniques to be used.
- A schedule and who is responsible for each part.
- The test environment: hardware, software and test data needed.
- Test cases: for each one, an ID, the purpose, the input data, the expected result, and space to record the actual result and whether it passed.
- Criteria for deciding when testing is complete.
| ID | Purpose | Input (days late) | Expected fine | Actual | Pass? |
| T1 | Not late | 0 | $0 | ||
| T2 | Inside first band | 5 | $5 | ||
| T3 | Boundary: last $1 day | 7 | $7 | ||
| T4 | Boundary: first $2 day | 8 | $9 | ||
| T5 | Cap reached | 40 | $30 |
Every test case should be traceable to a numbered requirement from the specification (Lesson 03). If a requirement has no test, nobody has checked it.
Part 3: Inspection and testing
There are two broad ways to find faults.
- Software inspection (static verification): people examine documents and code without running it. A small team, often including the author, reads the code line by line against a checklist (for example: are all variables initialised? does every loop end? does the code match the design?). Inspections can find many faults early and cheaply, including faults that tests may miss, such as poor structure or drift from the design (Lesson 07). Desk-checking with a trace table is a simple form of inspection.
- Software testing (dynamic verification): the program is run with test data and the actual results are compared with the expected results.
The two complement each other. Inspection is good at finding faults in logic and standards; testing is good at finding faults that only show up when the program runs with real data.
Part 4: Levels of testing
| Level | What is tested | Who | Library example |
| Unit (component) testing | Each module or function on its own. | The programmer | Test findBook with an ID that exists, one that does not, and the first and last books. |
| Integration testing | Modules combined, to check that they work together through their interfaces. | Programmers or a test team | Test recordLoan calling findBook; then recordReturn calling findLoan. |
| System testing | The whole system against the full requirements specification, including non-functional requirements. | An independent test team | Run a full day of loans, returns and reports; check search speed (2 seconds). |
| Acceptance testing | Whether the system meets the customer’s needs, using real or realistic data. | The customer and users | Library staff run their normal work on the system before signing it off. |
Integration testing matters because modules that pass their own unit tests can still fail together. Typical causes are mismatched interfaces: one module returns 0 for “not found” while its caller expects -1; one module sends a date as day number while the other expects DD/MM/YYYY; or two modules both change the same shared data. These faults are invisible until the modules are combined.
User testing: alpha, beta and acceptance
| Type | Where and by whom | Purpose |
| Alpha testing | At the developer’s site, by selected users or in-house testers, with developers watching. | Find faults and usability problems in a controlled setting before release. |
| Beta testing | At users’ own sites, by a group of real users, in normal use, without developers present. | Find faults that appear only in real conditions and on varied hardware; collect feedback. |
| Acceptance testing | By the customer, usually with real data, against agreed acceptance criteria. | Decide whether to accept (and pay for) the system. |
Try it 1Which kind of testing?
Choose the testing level or type that each story describes.
Part 5: Black-box testing
Black-box (functional) testing designs test cases from the specification only, treating the program as a closed box. The tester knows what the program should do but does not look at how it is coded. Use three kinds of test data:
| Kind of data | Meaning | Fine examples (days late) |
| Normal (typical) | Ordinary values well inside a valid range. | 3, 12 |
| Boundary (extreme) | Values at and just either side of the edges of each range, where faults hide most often. | 0, 1, 7, 8, 18, 19 |
| Erroneous (invalid) | Values that should be rejected or handled safely. | -2, or a letter typed instead of a number |
The fine rule (“$1 a day for days 1 to 7, then $2 a day, never more than $30”) splits the input into equivalence classes: not late (0 or less), first band (1 to 7), second band (8 and over, below the cap), and capped. One normal value from each class, plus the boundaries between classes, gives strong coverage with few tests. The cap is reached when 7 + (d – 7) × 2 exceeds 30, which first happens at 19 days, so 18 and 19 are a boundary pair.
Worked example: running the tests in C
Instead of typing each input by hand, put the test cases in two arrays and let a loop check them all. Here is a version of the fine function containing a fault, tested with the black-box cases:
#include <stdio.h>
#define MAXFINE 30
/* fine: dollars owed for d days late.
$1 a day for days 1-7, $2 a day
after that, never more than $30. */
int fine(int d)
{
int f;
if (d <= 0)
f = 0;
else if (d <= 7)
f = d;
else
f = d * 2; /* fault */
if (f > MAXFINE)
f = MAXFINE;
return f;
}
int main(void)
{
int in[] =
{-2, 0, 1, 7, 8, 18, 19, 40};
int want[] =
{ 0, 0, 1, 7, 9, 29, 30, 30};
int n = 8, pass = 0;
for (int i = 0; i < n; i++) {
int got = fine(in[i]);
int ok = (got == want[i]);
printf("%3d: %2d want %2d %s\n",
in[i], got, want[i],
ok ? "PASS" : "FAIL");
pass += ok;
}
printf("%d of %d tests passed\n",
pass, n);
return 0;
}
Output:
-2: 0 want 0 PASS 0: 0 want 0 PASS 1: 1 want 1 PASS 7: 7 want 7 PASS 8: 16 want 9 FAIL 18: 30 want 29 FAIL 19: 30 want 30 PASS 40: 30 want 30 PASS 6 of 8 tests passed
Two tests fail, and both are in the second band. The tests do not say where the fault is, only which inputs go wrong. That is enough to direct the programmer to the else branch, where the formula charges $2 for every day instead of only the days after 7. Notice that the normal value 40 passed, because the cap hid the fault. Only the boundary values exposed it.
#include <stdio.h>
#define MAXFINE 30
/* fine: dollars owed for d days late.
$1 a day for days 1-7, $2 a day
after that, never more than $30. */
int fine(int d)
{
int f;
if (d <= 0)
f = 0;
else if (d <= 7)
f = d;
else
f = 7 + (d - 7) * 2;
if (f > MAXFINE)
f = MAXFINE;
return f;
}
int main(void)
{
int in[] =
{-2, 0, 1, 7, 8, 18, 19, 40};
int want[] =
{ 0, 0, 1, 7, 9, 29, 30, 30};
int n = 8, pass = 0;
for (int i = 0; i < n; i++) {
int got = fine(in[i]);
int ok = (got == want[i]);
printf("%3d: %2d want %2d %s\n",
in[i], got, want[i],
ok ? "PASS" : "FAIL");
pass += ok;
}
printf("%d of %d tests passed\n",
pass, n);
return 0;
}
Output:
-2: 0 want 0 PASS 0: 0 want 0 PASS 1: 1 want 1 PASS 7: 7 want 7 PASS 8: 9 want 9 PASS 18: 29 want 29 PASS 19: 30 want 30 PASS 40: 30 want 30 PASS 8 of 8 tests passed
Part 6: White-box testing
White-box (structural, or glass-box) testing designs test cases by looking inside the code, so that every statement and every branch is exercised at least once. For fine, the code has these decisions:
| Decision | True branch needs | False branch needs |
| d <= 0 | d = 0 (or negative) | d = 1 or more |
| d <= 7 (when d > 0) | d from 1 to 7 | d = 8 or more |
| f > MAXFINE | d = 19 or more | d = 18 or less |
The tests -2, 1, 8 and 40 together take every branch at least once (branch coverage). A white-box tester also notices things a black-box tester cannot, such as a branch that can never be reached, or a variable used before it is given a value.
| Black-box | White-box | |
| Based on | The specification | The code’s structure |
| Tester needs | No knowledge of the code | Knowledge of the code |
| Good at finding | Missing or wrong functions, boundary faults | Untested paths, unreachable code, logic faults |
| Typical level | System and acceptance testing | Unit testing |
Try it 2Black-box or white-box?
Decide which approach each tester is using.
Try it 3Test data drill
“Data” asks you to classify test data for the fine rule ($1 a day for days 1 to 7, $2 a day after, cap $30). “Terms” checks testing vocabulary.
Common mistakes
- Testing only normal data. Most faults are found at boundaries.
- Writing a test case with no expected result. Without it, you cannot tell whether the test passed.
- Confusing alpha and beta testing. Alpha is at the developer’s site; beta is at users’ sites.
- Thinking unit tests are enough. Modules that pass alone can fail together.
- Saying black-box testing "looks at the code". It uses the specification only.
- Claiming testing proves there are no faults. It can only show faults that exist.
Summary
| Idea | Key point |
| Why test | Find faults early and cheaply; build confidence; show requirements are met. |
| Verification vs validation | Built right (spec) vs right product (user needs). |
| Test plan | What, how, who, when; test cases with expected results. |
| Inspection | Static: read code against a checklist without running it. |
| Levels | Unit, integration, system, acceptance. |
| User testing | Alpha (developer site), beta (user sites), acceptance (customer sign-off). |
| Black-box | From the specification: normal, boundary, erroneous data. |
| White-box | From the code: cover every statement and branch. |
Review questions
1. Give TWO reasons why software must be tested.
Show answer
To find faults before users do, when they are cheaper to fix; to show that the system meets its specification and users’ needs; to build confidence before release.
2. Distinguish between verification and validation.
Show answer
Verification checks that the software matches its specification and design ("built right"). Validation checks that it meets the users’ real needs ("right product").
3. List FOUR items in a test plan.
Show answer
Any four: items to be tested; approach and techniques; schedule and responsibilities; test environment and data; test cases with inputs and expected results; completion criteria.
4. What is software inspection, and how does it differ from software testing?
Show answer
Inspection is examining code or documents without running them, usually by a team using a checklist. Testing runs the program with test data and compares actual with expected results.
5. Explain the difference between unit testing and integration testing.
Show answer
Unit testing checks each module on its own. Integration testing checks that modules work correctly when combined, mainly through their interfaces.
6. Two modules each pass their unit tests but fail when combined. Suggest a reason and name the level of testing that should find it.
Show answer
A mismatched interface, for example one returns 0 for not found while the caller expects -1, or they disagree on a data format. Integration testing.
7. Distinguish between alpha and beta testing.
Show answer
Alpha testing is done by selected users or in-house testers at the developer’s site with developers present. Beta testing is done by real users at their own sites in normal use, before final release.
8. Compare black-box and white-box testing.
Show answer
Black-box testing designs cases from the specification without looking at the code (normal, boundary, erroneous data). White-box testing designs cases from the code to cover every statement and branch.
Homework
- A school awards grades: 0 to 49 F, 50 to 64 C, 65 to 79 B, 80 to 100 A. Write a black-box test plan with at least ten test cases, including all boundaries and two erroneous values.
- Write the grade function in C and a test harness like fine_fixed.c. Introduce one boundary fault on purpose and show that your tests catch it.
- For your grade function, list each decision and give a test for each true and false branch.
- Write a short paragraph explaining how alpha and beta testing could be used for a new school canteen app.
Mastery quiz: Validation and testing
This 10-question quiz is separate from the short Quick quiz at the end of the lesson. Score 8/10 or higher to earn this lesson’s badge. Your best score is saved in this browser on this device.
Mastery quiz: Validating Software: Test Plans, Black-Box and White-Box Testing
Your course badges: loading saved progress…
View badges
No course badges earned yet. Score 8/10 in a lesson quiz to earn its badge.
Saved in this browser on this device. Clearing browser data may remove your badges.
Answer all 10 questions. Earn this lesson’s badge at 8/10 or higher. Read the explanations, revisit the Try it activities and retry as often as you need. These are self-study badges, not formal grades.
Exam tips
Specimen Unit 2 Paper 01 (2021), Items 18 and 30. Item 18 describes testing individual parts of a system on their own; Item 30 describes parts that worked separately but failed when put together. Match "on its own" to unit or component testing and "together" to integration testing.
In structured questions, when asked for test data, give a value and say whether it is normal, boundary or erroneous, plus the expected result. When asked to distinguish two kinds of testing, compare who does it, where, when and why.
Previous: Unit 2 • Module 2 • Lesson 07 – From Design to Code: The Implementation Phase in C. Next: Unit 2 • Module 2 • Lesson 09 – Software Evolution and Maintenance.
Syllabus link: CAPE Computer Science (CXC A19/U2/21), Software Engineering (Unit 2, Module 2). Specific Objective 7: the validation phase, including why testing is needed, test plans, software inspection, software testing (unit, test-case design, system), user testing (alpha, beta, acceptance), and black-box and white-box testing.
Video search terms
Search YouTube for: "unit integration system acceptance testing", "alpha vs beta testing", "black box vs white box testing", "boundary value analysis equivalence partitioning".
Try it 4Quick quiz
Tap an answer. All eight questions are self-checks on this lesson.
Updates
2026/12/01
- First version of the lesson.
© 2026 islandclass.org
