Chapter 11, Unit Testing
Chapter 11, Unit Testing
Testing Activities
Subsystem Code Subsystem Code
User Manual
Tested Subsystem
Integration Test
Integrated Subsystems
Functional Test
Functioning System
Tested Subsystem
Subsystem Code
Unit Test
User Environment
Test
Acceptance Test
Installation Test
Usable System
System in Use
3
Unit Testing
Informal:
Incremental coding
Static Analysis:
Hand execution: Reading the source code Walk-Through (informal presentation to others) Code Inspection (formal presentation to others) Automated Tools checking for syntactic and semantic errors departure from coding standards
Dynamic Analysis:
Black-box testing (Test the input/output behavior) White-box testing (Test the internal logic of the subsystem or object) Data-structure based testing (Data types determine test cases)
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 4
1. Select what has to be measured Code tested for correctness with respect to:
requirements architecture detailed design
The test oracle has to be written down before the actual testing takes place This is the difficult step
5
Black-box Testing
Focus: I/O behavior. If for any given input, we can predict the output, then the module passes the test.
Almost always impossible to generate all possible inputs ("test cases") need techniques to define the input values
Derive tests using the detailed design Goal: Reduce number of test cases by equivalence partitioning:
Divide input conditions into equivalence classes Choose test cases for each equivalence class. (Example: If an object is supposed to accept a negative number, testing one negative number is enough)
Input is valid if it is from a discrete set. Select test cases from 2 equivalence classes:
White-box Testing Focus: Thoroughness (Coverage) Derive tests using the source code Four types of white-box testing Statement Testing Loop Testing Path Testing Branch Testing
Statement Testing:
Select and test single statements
Loop Testing:
Cause execution of the loop to be skipped completely
Path testing:
Make sure all paths in the program are executed
Branch Testing (Conditional Testing): Make sure that each possible outcome from a condition is tested at least once
if ( i = TRUE) printf("YES\n");else printf("NO\n"); Test cases: 1) i = TRUE; 2) i = FALSE
Unit Level
We can use the same testing approaches (whitebox, blackbox) in testing the classes The same testing activities occur, but now they are applied at a lower level of abstraction
10