Skip to content
Cambridge AS & A Level9618

Program Testing and Maintenance

Computer Science 9618 Chapter Notes

Last updated November 2026

ShareWhatsAppPost

Program Testing and Maintenance notes as a printable PDF.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full Program Testing and Maintenance notes as text: skim, search, and jump between subtopics.

~15 min read

1. Syntax, logic and run-time errors

A syntax error breaks the rules of the programming language, so the program cannot be compiled or run. A program with no syntax errors obeys the rules / grammar of the programming language.

A logic error is a fault in the algorithm or design: the program runs but does not give the expected output, for example a wrong operator or a wrong loop count.

A run-time error happens while the program runs, when it performs an illegal instruction or invalid operation, for example divide by zero or an endless loop.

Examiner insight

“The answer ‘there are no syntax errors’ was seen on relatively few occasions. Many answers were vague or inaccurate.”

Worked example 13 marks

Sylvia is testing a program that has been written by her colleague. Her colleague tells her that the program does not contain any syntax errors.

(i) State what her colleague means by “does not contain any syntax errors”.

(ii) Identify and describe one other type of error that the program may contain.

  1. 1

    (i) The program obeys the rules / grammar of the programming language used. [1]

  2. 2

    (ii) Type of error: logic error. [1]

  3. 3

    Description: an error in the algorithm / design, so the program does not behave as expected, e.g. a wrong arithmetic operator. [1]

2. Exposing faults

A fault that does not show itself needs a method that exposes it. Four are credited: dry run the code or produce a trace table; add output statements so the program can be tracked; use a breakpoint, single-stepping or a watch window in the IDE; try different test values to see which ones fail.

A breakpoint stops execution at a chosen line. Single-stepping executes one line at a time. The report (watch) window shows the values of variables. Used together they locate an error.

Examiner insight

“Popular incorrect answers were context-sensitive prompts and pretty printing which are tools for coding rather than debugging.” “Many general terms relating to testing were given.”

Worked example 12 marks

The FormatName() procedure should assign a value to the global variable FString. There is a fault in the program, which means that the assignment does not always take place.

Explain two ways of exposing the fault.

  1. 1

    Dry run / produce a trace table / walk through the code. [1]

  2. 2

    Insert a breakpoint, use single-stepping or monitor variables in a watch window (or add output statements, or try different test values to see which fail). [1]

3. Correcting and amending a program

To correct an error, say what is wrong and write what it should be. The clearest answers write the original statement and then the corrected one, both labelled.

Wrong operators cause logic errors: `>` for `<`, `&` for `+`, and `←` (assignment) where `=` (comparison) is meant.

Analysing a corrected program can still find a weakness to amend. In the program below, with its operators fixed, if all the numeric input values are greater than 999, or there are none, then the minimum will be given as 999 and not one of the input values.

Examiner insight

“The clearest answers were those which wrote both the original incorrect statement, followed by the correct (both labelled).”

Worked example 13 marks

An algorithm is designed to find the smallest numeric value from an input sequence and count how many numeric values have been input. Numeric input values are all integers and non-numeric input is ignored, except for the string "END" which is used to terminate the sequence.

``` Min ← 999 Count ← 0 REPEAT INPUT NextInput IF IS_NUM(NextInput) = TRUE THEN Num ← STR_TO_NUM(NextInput) IF Num > Min THEN Min ← Num ENDIF Count ← Count & 1 ENDIF UNTIL NextInput ← "END" ```

The pseudocode contains three errors due to the incorrect use of operators. Identify each error and state the correction required.

  1. 1

    `Num > Min` should be `Num < Min` [1]

  2. 2

    `Count & 1` should be `Count + 1` [1]

  3. 3

    `NextInput ← "END"` should be `NextInput = "END"` [1]

4. Black-box testing, dry runs and walkthroughs

Black-box testing is completed without referring to the code.

A dry run or walkthrough goes through the program a line / statement at a time, usually with a trace table. It needs the program code and a test plan, because the aim is to test every path through the program.

Errors show when a variable or an output gives an unexpected value.

Examiner insight

“Candidates sometimes provided vague answers such as ‘The walkthrough method is used to check for errors’. To gain credit, answers need to be more specific and detail how the errors are actually identified.” “Better answers stated that the key requirement was to test every possible path through the code.”

Worked example 13 marks

Once the program has been completed, it is tested using the walkthrough method.

Describe the walkthrough method and explain how it can be used to identify errors.

  1. 1

    Going through the program a line / statement at a time (a dry run). [1]

  2. 2

    Creating a trace table. [1]

  3. 3

    Errors are indicated when a variable / output gives an unexpected value. [1]

5. Integration and stub testing

Integration testing is carried out as program modules are being combined. Each module is tested on its own first, then added to the program and tested again.

When a module does not work once added, stub testing lets testing continue. A dummy / simple module replaces the module that does not work. The stub returns an expected value or outputs a message to show it has been called.

Examiner insight

“Many answers described the replacement of the faulty module with dummy module, but fewer mentioned that these would generate a known or expected result.”

Worked example 13 marks

The program modules SuppExists(), IsNewSupp() and CheckNewItem() are part of a group of modules that are combined to create a complete stock control program. Each module in the program is tested individually during development and is debugged as necessary. It is then added to the program and further testing performed.

(i) Identify this method of testing.

(ii) One of the modules does not work properly when it is added to the program. Describe a testing method that can be used to address this problem so that testing can continue and other modules can be added.

  1. 1

    (i) Integration testing. [1]

  2. 2

    (ii) A dummy / simple module is written to replace the module that does not work properly. [1]

  3. 3

    The dummy module will return an expected value, or output a message to show it has been called. [1]

6. Alpha, beta and acceptance testing

Alpha testing is carried out as soon as a program module has been coded. Beta testing is carried out by a small group of (potential) users before the program is sold.

Beta testers check that the software works as required in the real world and feed back problems and suggestions. These are addressed before release. Acceptance testing is the final stage, completed by the customer.

Examiner insight

“Answers that simply referred to the program being ‘tested’, were not sufficient, as this was given in the question.”

Worked example 14 marks

The program will be sold to the public. All the software errors that were identified during in-house testing have been corrected.

Identify and describe the additional test stage that may be carried out before the program is sold to the public.

  1. 1

    Test stage: beta testing. [1]

  2. 2

    Carried out by a small group of (potential) users. [1]

  3. 3

    Users check that the software works as required / in the real world and feed back problems or suggestions. [1]

  4. 4

    Problems and suggestions identified are addressed before the program is sold. [1]

7. Test plans and test data

A test plan lists the test data to be input and the expected result for each, so every test can be checked against what should happen. Each row gives the type of test data, the value and the expected outcome.

There are three types. Normal data is inside the range. Boundary / extreme data is at or next to a limit of the range. Abnormal data is outside the range.

For a range of 24 to 37 inclusive, 30 is normal, 24 and 37 are boundary, and 12 and 99 are abnormal. The values just outside, 23 and 38, are credited as abnormal or boundary.

Examiner insight

“A common mistake was using test data that was too similar to the example given in the question.”

Worked example 14 marks

The program contains a validation function.

The function will:

  • take an integer value as a parameter
  • return TRUE if the value is within the range 24 to 37, inclusive
  • otherwise return FALSE.

Complete the table to define a test plan to thoroughly test the operation of the function.

Type of test dataTest data valueExpected result
Normal30TRUE
  1. 1

    Abnormal: 12, expected FALSE [1]

  2. 2

    Boundary: 24, expected TRUE [1]

  3. 3

    Boundary: 37, expected TRUE [1]

  4. 4

    Abnormal / boundary: 38, expected FALSE (one mark per correct row; 23, 25, 36 or 99 are also credited) [1]

8. Perfective, adaptive and corrective maintenance

A system needs continuing maintenance after it is released. There are three types. Corrective maintenance is needed when the program does not operate as expected / contains a bug. Adaptive maintenance is needed to accommodate a change in the requirement / technology / legislation, such as new hardware. Perfective maintenance improves a program that works, for example changes to improve its speed of response.

Examiner insight

“Some answers tried to expand on the question scenario of ‘new hardware’ and this did not gain credit.”

Worked example 14 marks

A program has been written to implement a website browser and maintenance is now required.

One type of maintenance is called perfective.

Name two other types of maintenance that the program may require and give a reason for each.

  1. 1

    Type: adaptive. [1]

  2. 2

    Reason: to accommodate a change in the requirement / technology / legislation, e.g. a new HTML version is available. [1]

  3. 3

    Type: corrective. [1]

  4. 4

    Reason: the program does not operate as expected / contains a bug, e.g. passwords are not hidden. [1]

Recap

  • Syntax error: breaks the rules of the language. Logic error: wrong algorithm, wrong output. Run-time error: illegal operation while running.
  • Expose a fault with a dry run, trace table, output statements, breakpoint, single-stepping or watch window.
  • Correct an error by writing the faulty statement and its corrected version.
  • Black-box: without referring to the code. Walkthrough: line by line with a trace table.
  • Integration: modules combined. Stub: dummy module returning an expected value.
  • Alpha: as soon as a module is coded. Beta: small group of potential users. Acceptance: the customer, final stage.
  • Test plan: type of test data, value, expected result. Normal, boundary / extreme, abnormal.
  • Corrective fixes bugs. Adaptive meets a change. Perfective improves a working program.

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. State what is meant by a syntax error.1 mark
    Answer
    1. The program breaks the rules (grammar) of the programming language.

    Trap: A wrong output is a logic error, not a syntax error.

  2. Identify the type of error in each case. (a) A program divides a total by a count, and the count is 0 when the program runs. (b) A program is meant to add two numbers but the programmer writes `*` instead of `+`.2 marks
    Answer
    1. (a) Run-time error: an invalid operation (divide by zero) while the program runs.
    2. (b) Logic error: the program runs but gives the wrong result.

    Trap: Divide by zero gives a wrong or no answer, but it is a run-time error because the program fails while running.

  3. A program reads three marks and outputs their average. The marks 4, 8 and 6 are input. ``` Total ← 0 FOR Index ← 1 TO 3 INPUT Mark Total ← Mark NEXT Index Average ← Total / 3 OUTPUT Average ``` Carry out a dry run to state the value output. Identify the fault and write the corrected statement.3 marks
    Answer
    1. Total takes the values 4, 8, 6. The last is 6, so Average = 6 ÷ 3 = 2.
    2. Fault: `Total ← Mark` replaces the total each time instead of adding to it.
    3. Correction: `Total ← Total + Mark`, which gives 18 ÷ 3 = 6.

    Trap: The expected average is 6, not 2, so the output only looks plausible. Compare with the expected value.

  4. Name the test method that is completed by the developers without referring to the code.1 mark
    Answer
    1. Black-box testing.

    Trap: A walkthrough or dry run needs the program code, so it cannot be the method that does not refer to the code.

  5. A module of a stock program does not work when it is added to the complete program. State the testing method that lets testing continue with the other modules and describe it.3 marks
    Answer
    1. Stub testing.
    2. A dummy / simple module replaces the module that does not work.
    3. The dummy module returns an expected value (or outputs a message to show it has been called).

    Trap: A stub is a dummy module, not a dummy program, and it does not check anything. It returns an expected value.

  6. A company gives its new app to 200 selected members of the public to use before it goes on sale. State the name of this test stage and describe two things the users do.3 marks
    Answer
    1. Beta testing.
    2. The users check that the software works as required in the real world.
    3. The users feed back problems or suggestions for improvement.

    Trap: ‘Testing’ alone is not credited. Name the stage, and do not confuse it with alpha, which is as soon as a module is coded.

  7. Name the type of maintenance in each case. (a) A bug that crashes the program when a name contains an apostrophe is fixed. (b) The program is changed because the law on sales tax has changed. (c) A search routine is rewritten so that results appear faster.3 marks
    Answer
    1. (a) Corrective: it fixes a bug.
    2. (b) Adaptive: it accommodates a change in legislation.
    3. (c) Perfective: it improves a working program (speed of response).

    Trap: Faster is an improvement to a program that already works (perfective), not a change in requirements (adaptive).

  8. A function returns TRUE if the number of players entered is a whole number from 2 to 6 inclusive, otherwise FALSE. Complete a test plan of four tests that includes both limits of the range, one value outside it, and one normal value. Give the type of test data, the value and the expected result.4 marks
    Answer
    1. Normal: 4, expected TRUE.
    2. Boundary / extreme: 2, expected TRUE.
    3. Boundary / extreme: 6, expected TRUE.
    4. Abnormal: 7 (or 1), expected FALSE.

    Trap: Off by one: 6 is accepted and 7 is the first rejected value. Testing only values well inside or well outside the range misses the limits.

  9. A program reads whole numbers until -1 is input and outputs the largest. The -1 is not part of the data. ``` Largest ← 0 INPUT Num WHILE Num <> -1 IF Num > Largest THEN Largest ← Num ENDIF INPUT Num ENDWHILE OUTPUT Largest ``` (a) Identify the type of error in the algorithm. (b) Give a test data sequence that shows the error, and state the output and the expected output. (c) Write a correction.5 marks
    Answer
    1. (a) Logic error: the program runs but gives a wrong output for some data.
    2. (b) Test data: -7, -3, -1 (all values negative, ending with the terminator).
    3. Output: 0.
    4. Expected output: -3.
    5. (c) Delete `Largest ← 0` and put `Largest ← Num` after the first `INPUT Num`, before the loop.

    Trap: Positive test data gives the right answer, and a sequence without the -1 terminator never ends: the data must end with -1 and use only values below the starting value of 0.

  10. A function Discount(Qty) should return -1 if Qty is outside 1 to 200 inclusive. Otherwise it returns the percentage discount: 0 for 1 to 9, 5 for 10 to 49, and 10 for 50 to 200. The programmer wrote: ``` FUNCTION Discount(Qty : INTEGER) RETURNS INTEGER IF Qty < 1 OR Qty > 200 THEN RETURN -1 ENDIF IF Qty > 50 THEN RETURN 10 ENDIF IF Qty >= 10 THEN RETURN 5 ENDIF RETURN 0 ENDFUNCTION ``` (a) A tester uses the test data 5, 30 and 100. State the value returned for each and explain why these tests do not expose the error. (b) Give the test value that exposes the error, the value returned and the expected result. (c) Write the corrected statement. (d) Give the two boundary values at the upper limit of the valid range, with their expected results.7 marks
    Answer
    1. (a) 5 returns 0, 30 returns 5, 100 returns 10: all as expected.
    2. They are normal data in the middle of each band, so no test reaches the limit at 50 where the comparison is wrong.
    3. (b) 50 returns 5.
    4. Expected result: 10.
    5. (c) `IF Qty >= 50 THEN`
    6. (d) 200, expected 10.
    7. 201, expected -1.

    Trap: Values in the middle of each band (normal data) all pass, so the wrong comparison `>` for `>=` is only found by testing the boundary value 50.

Say this, not that

Wording that loses the mark, against the wording the mark scheme credits.

Loses the markGets the mark
A stub is a dummy program that checks the module.A stub is a dummy / simple module that replaces the faulty one and returns an expected value.
The walkthrough method is used to check for errors.Go through the code a line at a time, with a trace table; an error shows as an unexpected value.
Beta testing is when the program is tested.Beta testing is by a small group of potential users who feed back problems before sale.
The IDE helps with debugging by pretty printing and context-sensitive prompts.Debugging tools: breakpoint, single-stepping, report window.

Frequently asked questions

What is the difference between a syntax error, a logic error and a run-time error?
A syntax error breaks the rules of the programming language, so the program cannot be compiled or run. A logic error is a fault in the algorithm or design: the program runs but does not give the expected output. A run-time error happens while the program runs, for example divide by zero or an endless loop.
How do you correct an error in a program?
Say what is wrong and write what it should be. The clearest answers write the original statement and then the corrected one, both labelled. Wrong operators cause logic errors, for example > for <, & for +, or <- where = is meant.
Are pretty printing and context-sensitive prompts debugging tools?
No. Pretty printing and context-sensitive prompts are tools for coding rather than debugging. The debugging tools to name are a breakpoint, single-stepping and the report window. A breakpoint stops execution at a chosen line, and single-stepping executes one line at a time.
What is stub testing?
Stub testing is used when a module does not work once it is added to the program. A dummy or simple module replaces the faulty module so that testing can continue. The stub returns an expected value or outputs a message to show it has been called.
What should a test plan include?
A test plan lists each test data value and its expected result. Each row gives the type of test data, the value and the expected outcome. The three types are normal, boundary or extreme, and abnormal. For a range of 24 to 37 inclusive, 30 is normal, 24 and 37 are boundary, and 12 and 99 are abnormal.
What is the difference between corrective, adaptive and perfective maintenance?
Corrective maintenance fixes a bug, when the program does not operate as expected. Adaptive maintenance accommodates a change in the requirement, technology or legislation. Perfective maintenance improves a program that works, for example its speed of response.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters