120 likes | 246 Vues
Learn about statement coverage and branch coverage in software testing and solve exercises to enhance your understanding. References from Boris Beizer's book. Includes practice exercises and suggested solutions for effective testing strategies.
E N D
Statement coverage and Branch coverage • Statement coverage – “Execute all statements in the program at least once under some test.” • Branch coverage – “Execute enough tests to assure that every branch alternative has been exercised at least once under some test.” References: Boris Beizer, Software Testing Techniques 2nd edition, 1990 (page 74).
Notes • Assuming that red dots are global definition and green dot is the global c-use. • **The following is not a du-path: • Hence, when you are answering du-paths questions, please make sure that the path fulfills the requirements.
x=read(x) y=read(y) max=x x<y 1 2 3 4 x>y max = y 5 Exercise • Findpaths for x that satisfy the following criteria: • All-defs: • All-uses: • All-p-uses: • All-c-uses: • All-du-paths:
x=read(x) y=read(y) max=x x<y 1 2 3 4 x>y max = y 5 Exercise • Findpaths for x that satisfy the following criteria: • All-defs: {1,2,3} • All-uses:{1,2,3}, {1,2,3,4}, {1,2,3,5}, • All-p-uses: {1,2,3,4}, {1,2,3,5} • All-c-uses: {1,2,3} • All-du-paths = all-uses + {1,2,3,4,5}
Suggested solutions • 0 • 0, 1 • Not possible because the loop does not have a fixed upper bound. We don’t know the value of “n” to execute the loop n-1, n and n+1 times. • Infinite number of test cases because the loop does not have a fixed upper bound. • Global definition: 1-2-3-4-5, 9-10 Global c-uses: 9-10, 11 du-paths: 1-2-3-4-5 9-10 1-2-3-4-5 7 9-10 1-2-3-4-5 11 9-10 9-10 9-10 11
An extra question • Propose test cases to achieve all-du-paths criterion of the variable “factorial”.
Solutions • 3 test cases: 3, 1, 0. • Remarks: • N = 3 • 1-2-3-4-5 9-10 9-10 11 • N = 0 • 1-2-3-4-5 7 9-10 11 • N = 1 • 1-2-3-4-5 11