Unit Testing
Unit testing focuses on verifying the smallest functional part of a software design, typically a component or module. It is a white-box oriented technique, meaning the internal workings and logic of the code are known and tested. The primary goal is to ensure that the component works correctly in isolation before it is integrated with the rest of the system. Think of it as making sure each LEGO brick is perfectly shaped before you try to build the whole spaceship.
Unit Testing Strategies
- Focus on the Smallest Unit: The verification effort is aimed at the smallest unit of software design, such as a component or module.
- Design as a Guide: The component-level design description is used to guide the testing process.
- Control Paths: Key control paths within the boundary of the module are identified and tested to uncover errors.
- White-Box Oriented: The unit test is white-box oriented, meaning the internal structure is known, and test cases are designed based on that knowledge.
- Parallel Execution: The testing steps can be performed in parallel for multiple components.
Unit Test Considerations
- Module Interface: Ensuring information flows correctly into and out of the unit.
- Local Data Structures: Checking that temporarily stored data within the module maintains its integrity.
- Boundary Conditions: Verifying that the module operates correctly at the established limits or restrictions (e.g., maximum/minimum values).
- Independent Paths: Guaranteeing that all statements in a module have been executed at least once (Basis path and loop testing are used here).
- Error Handling Paths: Finally, testing how the module handles and processes all potential errors.
Errors Commonly Found During Unit Testing
Computation Errors:
- Misunderstood or incorrect arithmetic precedence.
- Mixed mode operations
- Incorrect init or precision inaccuracy
- Incorrect symbolic representation of an expression