Correct identified errors

12.3 Program Testing and Maintenance

Testing is like checking a recipe before you cook. You try each step to catch mistakes early, so the final dish (your program) turns out just right. Maintenance is the ongoing care you give to that dish after it's served – fixing any issues that arise and improving it over time.

What is Program Testing?

Testing is the systematic process of executing a program with the goal of finding bugs (errors) and ensuring it behaves as expected.

Think of it as a detective 🕵️‍♂️ who follows clues (test cases) to uncover hidden problems.

Types of Testing

  • Unit testing – test each small part (function or method) in isolation.
  • Integration testing – test how multiple parts work together.
  • System testing – test the entire program as a whole.
  • Acceptance testing – test whether the program meets user requirements.

Common Error Types

Type Description Example
Syntax error Wrong use of language rules (missing semicolon, wrong keyword). `if (x = 5)` instead of `if (x == 5)`.
Runtime error Error that occurs while the program is running (e.g., divide by zero). `int a = 10 / 0;`.
Logic error Program runs but gives wrong results. Calculating the average with `sum / (n-1)` instead of `sum / n`.
Boundary error Problem occurs at the edges of input ranges. Array index out of bounds when accessing `array[10]` in a 10‑element array.

Debugging Strategies

  1. 🔍 Reproduce the error – run the program again with the same input.
  2. 📄 Read the error message – it often points to the line or type of problem.
  3. 🐛 Insert print statements – show variable values at key points.
  4. 🧩 Use a debugger – step through code line by line.
  5. 🧠 Check the logic – verify each condition and loop behaves as intended.
  6. 🧪 Test edge cases – try minimum, maximum, and unusual inputs.
  7. ?? Fix and retest – make the change and run tests again to confirm.

Maintenance Types

  • Corrective maintenance 🐛 – fixing bugs found after release.
  • Adaptive maintenance 🔄 – updating the program for new hardware or software environments.
  • Perfective maintenance ⚙️ – improving performance or adding new features.
  • Preventive maintenance 🛡️ – refactoring code to avoid future problems.

Exam Tips

Understand the difference between testing and debugging. Testing is the process of finding errors; debugging is fixing them.

Know the four main types of testing. Be ready to explain when each is used.

Remember the error types. Use the table as a quick reference.

Practice writing test cases. Show how you would test a function that calculates the factorial of a number.

Use clear, concise language. In exam answers, explain steps logically and use examples.

Good luck! 🎯

Quick Math Check

The error rate can be expressed as $E = \frac{B}{T}$ where $B$ is the number of bugs found and $T$ is the total number of test cases run.

If you find 5 bugs in 200 test cases, the error rate is $E = \frac{5}{200} = 0.025$ (or 2.5%).

Revision

Log in to practice.

2 views 0 suggestions