Program Testing And Maintenance (Copy)
12.3.1 Ways of Avoiding and Exposing Faults in Programs
- Human Error in Programming
- Programmers make mistakes, which lead to faults in software.
- Goal: Minimize errors and detect as many as possible before deployment.
- Consequences of Faults
- Some major banks faced customer lockouts due to software faults.
- Airlines have had to cancel flights due to programming errors.
- A prison system mistakenly released prisoners early for 15 years due to a faulty program.
- Fault Prevention Strategies
- Comprehensive program specifications: A detailed and rigorous specification should be created during the analysis phase.
- Formal Methods: Techniques like structure charts, state-transition diagrams, and pseudocode help in design and testing.
- Programming disciplines: Concepts such as encapsulation, information hiding, and exception handling reduce faults.
- Fault Exposure in Testing
- Testing can only reveal faults; it cannot guarantee a completely error-free program.
- Large and complex programs might have undetected faults despite rigorous testing.
- Errors found after deployment must be corrected through maintenance.
12.3.2 Location, Identification, and Correction of Errors
- Types of Errors
- Syntax Errors: Errors in the grammar of the programming language. These are detected by compilers or interpreters.
- Example: A variable name is misspelled (
vvalue2instead ofvalue2).
- Example: A variable name is misspelled (
- Logic Errors: The program runs but does not produce the expected results.
- Example: A directional movement program incorrectly updates the X coordinate instead of Y.
- Run-time Errors: Errors that occur while the program is running, such as division by zero.
- Example: A division operation where the denominator becomes zero.
- Syntax Errors: Errors in the grammar of the programming language. These are detected by compilers or interpreters.
- Debugging Tools
- Trace Tables: Track variable values throughout execution to detect logic errors.
- Integrated Development Environments (IDEs): Provide debugging tools, such as breakpoints and step-by-step execution.
12.3.3 Program Testing
- Testing is Continuous
- Begins as soon as the program is written.
- Should be documented to prove robustness and readiness.
- Test Strategy
- A high-level overview of required testing.
- Shows how and when testing will be conducted.
- Test Plan
- Detailed documentation listing all testing stages and test cases.
- Includes test data, expected results, and actual results.
- Types of Testing
- White-box Testing: Tests the internal structure and logic of the program.
- Black-box Testing: Focuses on inputs and expected outputs without considering internal logic.
- Integration Testing: Ensures different program modules function together.
- Stub Testing: Uses dummy modules for testing when real modules are unavailable.
- Final Testing Phases
- Alpha Testing: Conducted in-house by the development team.
- Beta Testing: Done by external users before the program’s official release.
- Acceptance Testing: Ensures the software meets customer requirements before full deployment.
12.3.4 Program Maintenance
- Understanding Maintenance
- Unlike physical equipment, programs do not degrade over time.
- However, they might fail under unforeseen circumstances.
- Users may require new features, necessitating updates.
- Types of Program Maintenance
- Corrective Maintenance: Fixes errors that appear during use.
- Example: A program crashes due to a previously undetected run-time error.
- Perfective Maintenance: Enhances program performance.
- Example: Optimizing an algorithm to improve execution speed.
- Adaptive Maintenance: Modifies a program to meet new requirements.
- Example: Updating a program to support voice commands in addition to keyboard input.
- Corrective Maintenance: Fixes errors that appear during use.
Types of Test Data
- Normal Test Data
- Data that is expected and should be correctly processed.
- Example: Testing a function that adds two numbers with inputs
10and20.
- Abnormal Test Data
- Data that should be rejected by the program.
- Example: Inputting a string (
"twenty") into a numeric field.
- Extreme Test Data
- Data at the edge of acceptable limits.
- Example: If an input range is
12-32, testing with12and32.
- Boundary Test Data
- Data at the boundary of acceptable and unacceptable inputs.
- Example: If the valid range is
12-32, testing with11(invalid) and12(valid).
Practical Testing Example
- Sample Calculation Procedure
PROCEDURE calculation(number1, number2, sign) CASE sign OF '+' : answer ← number1 + number2 '-' : answer ← number1 - number2 '*' : answer ← number1 * number2 '/' : answer ← number1 / number2 OTHERWISE answer ← 0 ENDCASE IF answer <> 0 THEN OUTPUT answer ENDIF ENDPROCEDURE - Test Cases for Above Procedure
| Test Purpose | Test Data | Expected Outcome | Actual Outcome |
|---|---|---|---|
| Test addition | 20, 10, + |
30 | 30 |
| Test subtraction | 20, 10, - |
10 | 10 |
| Test multiplication | 20, 10, * |
200 | 200 |
| Test division | 20, 10, / |
2 | 2 |
| Test invalid sign | 20, 10, ? |
0 | 0 |
| Test division by zero | 20, 0, / |
Undefined | Error |
Conclusion
- Rigorous testing is essential to ensure program reliability and user satisfaction.
- A well-structured maintenance plan ensures software remains functional, efficient, and adaptable.
- Various testing techniques and data types help identify and fix errors at different stages of development.
- Effective program testing and maintenance contribute to long-term software success.
