Object-orientation helps analysis and design of large systems but, based on existing data, it seems that more testing is needed for OO software.
Unit testing techniques are applicable to classes, but OO software has specific constructs that we need to account for during testing (Encapsulation, Inheritance, Polymorphism, Abstract classes).
Main Differences
- Testing in OOP differs from in procedural programming since a basic component is a class rather than a function where our test here needs to include object state.
- Most of the complexity here lies in method interactions since the methods themselves are quite simple.
- Encapsulation may go against testing
- Due to polymorphism, there are multiple possible invocations of the same interfaces
- Each exception needs to be tested
- We need new fault models for defining testing methods and techniques targeting OO specific faults
- Ex:
- Wrong instance of method inherited in the presence of multiple inheritance
- Wrong redefinition of an attribute / data member
- Wrong instance of the operation called due to dynamic binding and type errors
- Ex:
Integration Levels
- Unit testing tests a single method of a class
- Unit testing also tests the integration of methods within a class
- Intra-class testing uses the classic Testing Techniques and is state-based
- We use the big bang approach in Integration Testing for situations where methods are tightly coupled
- Alpha-omega cycles are used
- Different scopes of Integration Testing are required
Since we require Test Drivers and Test Stubs, we need Mock Objects