160 likes | 370 Views
Software Testing. Component testing Testing of individual program components Usually responsibility of developer Tests derived from developer’s experience Integration testing Testing of groups of components integrated to create system or sub-system
E N D
Software Testing • Component testing • Testing of individual program components • Usually responsibility of developer • Tests derived from developer’s experience • Integration testing • Testing of groups of components integrated to create system or sub-system • Responsibility of independent testing team • Tests based on a system specification Ch20 - Software Testing I
Defect Testing • Goal:to expose latent system faults • Test cannot guarantee absence of faults • Exhaustive testing impractical • Successful defect test: • one which causes system to misbehave • finds a fault Ch20 - Software Testing I
Defect Testing Process Ch20 - Software Testing I
Black-box Testing • Tests based on inputs, expected outputs • Developed from specification, not implementation • How to select good test inputs? • Domain knowledge • Equivalence partitioning Ch20 - Software Testing I
Equivalence Partitioning • Divide inputs into equivalenceclasses, apply test cases from each class • Typical value (e.g. midpoint) • Boundary conditions • Kinds of equivalence classes • Valid/invalid inputs • Inputs for which system behave similarly • No need to test with incorrect arg types Ch20 - Software Testing I
Equivalence PartitioningExamples • Function to determine abs • Function to determine sin • Four quadrants: 0°-90°, 90°-180°, 180°-270°, 270°-360° • Searching for removing an element value from a list Ch20 - Software Testing I
Remove routine specification procedure Remove (Key : ELEM ; T: ELEM_ARRAY; Found : in out BOOLEAN; L: in out ELEM_INDEX) ; Pre-condition -- the array has at least one element T’FIRST <= T’LAST Post-condition -- the element is not present in the sequence ( not Found and not (exists i, T’FIRST >= i <= T’LAST, T (i) = Key )) Ch20 - Software Testing I
Remove routine input partitions • Inputs which conform to the pre-conditions • Inputs where a pre-condition does not hold • Inputs where the key element is a member of the array • Inputs where the key element is not a member of the array Ch20 - Software Testing I
Testing guidelines (sequences) • Tests when input argument is a sequence • with sequence length = 1 • with sequence length = 0 • with sequence length >> 0 • Different-length sequences • “Tickle” the first, middle and last elements of the sequence Ch20 - Software Testing I
White-box (Structural) Testing • Derive tests from study of implementation • Goal is to exercise all independent program paths (every statement) • not all dynamic paths through the program (not feasible) • Stronger, hard to do manually for complex programs • Dynamic program analyser can check paths have been executed Ch20 - Software Testing I
Program flow graphs • Each basic block is a node • Each branch is shown as a separate path; loops are drawn as arrows looping back to the loop condition node • Cyclomatic complexity = Number of edges - Number of nodes + 2 Ch20 - Software Testing I
Program flow graphsExample bool Remove(int key, intarray& array) { int origSize = array.size(); for (int i = 0; i < array.size(); i++) { while (array[i] == key) { int limit = array.size(); for (int j = i; (j+1) < limit; j++) { array[j] = array[j+1]; } array.shrink(-1); } } return (array.size < origSize); } Ch20 - Software Testing I
Program flow graphsExample bool Remove(int key, intarray& array) { int origSize = array.size(); for (int i = 0; i < array.size(); i++) { while (array[i] == key) { int limit = array.size(); for (int j = i; (j+1) < limit; j++) { array[j] = array[j+1]; } array.shrink(-1); } } return (array.size < origSize); } A B C D E F G H I Ch20 - Software Testing I
Program flow graphsExample END START A B I H C D F E G Ch20 - Software Testing I
Program flow graphsExample • Cyclomatic Complexity = 11 – 9 + 2 = 4 • Therefore, 4 Traces • A, B, I • Array of zero length • A, B, C, H, I • Array with no key in any slots • A, B, C, D, E, G, H, I • Array with key just in last slot • A, B, C, D, E, F, G, H, I • Array with key in some slots (but not just last slot) Ch20 - Software Testing I