12.3 Program Testing and Maintenance

2026 Syllabus Objectives

By the end of this subtopic, you should be able to:

  • understand ways of avoiding faults and exposing faults in programs
  • identify different types of errors: syntax errors, logic errors, and run-time errors
  • correct errors once they have been found
  • understand and use different testing methods, including dry run, walkthrough, white-box, black-box, integration, stub, alpha, beta, and acceptance testing
  • understand why a test strategy and a test plan are needed, and know what they usually contain
  • choose suitable test data for a test plan, including normal, abnormal, extreme, and boundary data
  • understand why software needs ongoing maintenance
  • explain the difference between corrective, perfective, and adaptive maintenance
  • analyse an existing program and make changes to improve what it does

Avoiding and exposing faults in programs

A fault is a problem in a program that may cause the program to behave in the wrong way. Faults matter because even a small mistake can cause a program to give wrong results, stop working, or behave unpredictably.

Programmers try to do two things:

  • avoid faults before the program is finished
  • expose faults by testing, so they can be found and corrected

Avoiding faults starts before any real coding begins. A programmer should work from a clear and detailed specification. This means the programmer should know exactly what the program is supposed to do, what inputs it accepts, what outputs it must produce, and what rules it must follow. If the specification is unclear, mistakes are much more likely.

Good design also helps to avoid faults. A programmer can use tools such as structure charts, state-transition diagrams, and pseudocode to plan the solution carefully before writing the full program. These design methods make the logic clearer and reduce confusion.

Careful programming methods also reduce faults. For example, programmers can separate parts of a program into modules, keep data protected inside modules where possible, and handle unusual situations properly. These methods do not remove all faults, but they make faults less likely.

Even with careful design, faults can still appear because programmers are human and can make mistakes. This is why testing is so important. Testing helps to expose faults, which means it helps to reveal problems that are hidden inside the program.

It is important to remember that testing can show that faults exist, but testing cannot prove that a program is completely perfect. A program may still contain faults that were not discovered during testing.


Types of errors

There are three main types of errors you need to know: syntax errors, logic errors, and run-time errors.

Syntax errors

A syntax error happens when the rules of the programming language are broken. In simple words, the program has been written in a form the computer cannot understand properly.

Because the program is written incorrectly, it usually will not run until the syntax error is fixed.

Common causes of syntax errors include:

  • spelling a variable name wrongly
  • missing punctuation or brackets
  • using the wrong symbol for assignment
  • writing a function call in the wrong format

For example, imagine a program contains this:

total = value1 + vvalue2

If the correct variable name is value2, then vvalue2 is a spelling mistake. The computer may flag this as an error because that variable does not exist.

Syntax errors are often easier to find than other errors because an IDE or translator usually reports them straight away.

Logic errors

A logic error happens when the program runs, but gives the wrong answer. The instructions are valid, so the program does not stop. However, the steps are wrong.

This is often more dangerous than a syntax error, because the program may look as if it is working when it is actually producing incorrect results.

For example, suppose a program is supposed to subtract two numbers, but it adds them instead. The program still runs, but the answer is wrong.

In one example, a calculation procedure was tested with subtraction data, but instead of giving the answer 10, it gave 30. This shows a logic error in the subtraction part of the code.

Logic errors are usually found during testing, especially by using trace tables, dry runs, and carefully chosen test data.

Run-time errors

A run-time error happens while the program is running. The program starts, but then a problem occurs during execution.

This kind of error may cause the program to stop suddenly, crash, or behave unexpectedly.

Common causes include:

  • dividing by zero
  • trying to use data that does not exist
  • trying to access an array element outside its valid range
  • calling something incorrectly during execution

For example, if a program tries to calculate 20 / 0, the program may stop because division by zero is not allowed.

Another example is passing the wrong number of values to a function. The program may start normally, but fail when it reaches that line.

Sign in to view full notes