- Year not given · 5 marks
Exception and error testing
What is exception and error testing?
Exception and error testing (error-handling testing) checks that the software detects abnormal conditions and handles them correctly: it should report a clear message, protect data, and either recover or fail safely, instead of crashing or producing wrong results. A well-designed program anticipates errors and has error-handling paths, and these paths must be tested just like normal paths.
What is tested
- Invalid inputs: wrong type, out-of-range values, empty fields, very long strings.
- Exceptions thrown by code: divide by zero, null reference, array index out of bounds, file not found, overflow.
- External failures: database or network down, disk full, time-out, hardware failure.
- Recovery: after the error, the system returns to a consistent state (transactions rolled back, resources released).
Typical error-handling faults (Pressman)
- The error description is unintelligible to the user.
- The error noted does not match the error actually encountered.
- The error condition causes system intervention (crash) before error handling runs.
- Exception-condition processing is incorrect.
- The error description does not give enough information to find the cause.
Techniques
- Use invalid equivalence classes and boundary values as test inputs.
- Fault injection: deliberately cause failures (e.g. disconnect the database) to see how the system reacts.
- White-box coverage of every
catch/error branch. - Recovery testing: force the software to fail and check that it recovers within the required time.
- Unit-test frameworks can assert that an exception is thrown, e.g. JUnit
assertThrows(ArithmeticException.class, () -> divide(5, 0)).
Example
In a bank transfer feature:
| Test | Expected handling |
|---|---|
| Amount = −500 | "Invalid amount" message, no transfer |
| Amount > balance | "Insufficient balance", balance unchanged |
| Network drops mid-transfer | Transaction rolled back, user informed |
| Wrong account number | "Account not found" message |
Exception and error testing improves robustness and reliability, since many real failures come from conditions that the normal tests never exercise.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Exception handling over conventional error handling · Object Oriented Programming, chapter 10
- Exception handling: OO vs conventional · Object Oriented Analysis and Design, chapter 4
- Types of error; single proportion test · Probability and Statistics, chapter 7 · asked 2×