Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
11S3112 PPMPL
White Box Testing : Control Flow Coverage Part 1
Week 4 Session 1Tahun Ajaran 21/22
Lecturer : ACB Teaching Assistant: Apria
- PPMPL 11S3112–- Sem Ganjil 2021/2022 -
Institut Teknologi DelJl. SisingamangarajaSitoluama, Laguboti 22381Toba – SUMUThttp://www.pidel.org
• What is white box testing ?• Advantages and disadvantages• Importance of coverage based testing• Control flow coverage• Test suite generation using coverage
based testing
9/12/21 ACB
Overview
• Known as code-based testing or glass box testing or structural testing
• Generate test cases based on the program source and on the internal workings of the source
9/12/21 ACB
What is White Box Testing ?
9/12/21 ACB
White Box Testing – A common view
PROGRAM…IF (a>b) then
Do somethingElse
Do other Things….
INPUT OUTPUT
TEST CASE SELECTION STRATEGIES
• Advantagesq Test implemented modules, specially ones that have not been specifiedq Therefore faults in such modules can be detected, but not in black box
testing
• Disadvantagesq Not test specified but not implemented modules (why is this important?)q Testing cannot be conducted before coding / implementation completedq Need to have programming skills
9/12/21 ACB
Advantages and Disadvantages
• Coverage testing: a certain part of the program is not covered, we cannot know whether there are faults inside that part.
• Coverage criteriaq Control-flow coverageq Data-flow coverage
9/12/21 ACB
Intuition of white box testing
• Given a coverage criterion, list out all the items to be covered
• Find test cases to execute each item at least once
9/12/21 ACB
Procedure in coverage testing
• By program instrumentationInsert some printing statements to trace the program execution
9/12/21 ACB
How do we know that an item has beenexecuted?
• Control flow coverage testing:q statement coverage testingq branch / decision coverage testingq condition coverage (cc)qDecision/condition coverage (d/cc)q modified condition/decision coverage
(MC/DC)q multiple-condition coverage (M-CC)
• Data flow coverage testingq all-defs, all-c-uses, all-p-uses, all-c-
uses/some-p-uses, all-p-uses/some-c-uses, all-uses, and all-du-paths
9/12/21 ACB
Classification
• Node: A block of statements that is not separated by any branch
• Edge: link between nodes
• Branch: An edge, associated with the true or false branch of a decision node (or called predicate)For example, Node 2 (5th line of code) is a decision node, which has two out-going edges (b and d) b and d are called the branches of Node 2. Each edge is labeled as a character, that is, a, b, c, … in the next 2 slide
9/12/21 ACB
Node, Edge, and Branch
1 Sub F1 (int a, int b)2 {3 int z; \\ S14 z = 5 ; \\ S25 if (a>1) && (b==0) \\ S36 {7 a = a + 10; \\ S48 }9 z= z + a + b \\ S510 print z; \\ S611 }
9/12/21 ACB
Example: find the nodes
1 Sub F1 (int a, int b)2 {3 int z; \\ S1 N14 z = 5 ; \\ S2 5 if (a>1) && (b==0) \\ S3 N26 {7 a = a + 10; \\ S4 N38 }9 z= z + a + b \\ S5 N410 print z; \\ S611 }
9/12/21 ACB
Example: find the nodes
1Public int getExtraHours()2{3 int hours, i; //s14 hours = 0; //s25 i = 0; //s36 while (i < numSession) //s47 {8 if (session[i].status == EXTRA) //s59 {10 hours = hours + session[i].duration; //s611 }12 else 13 {14 hours = hours //s8 15 }16 i++; //s917}18return hours; //s1019}
Program under study:determine the nodes !
9/12/21 ACB
1Public int getExtraHours()2{3 int hours, i; //s1, node14 hours = 0; //s25 i = 0; //s36 while (i < numSession) //s4, node27 {8 if (session[i].status == EXTRA) //s5, node39 {10 hours = hours + session[i].duration; //s6, node411 }12 else 13 {14 hours = hours //s8, node 5 15 }16 i++; //s9, node617}18return hours; //s10, node719}
Program under study: The Nodes
9/12/21 ACB
9/12/21 ACB
Control Flow Graph
1
23
4
5
7
START
END6
1Public int getExtraHours()2{3 int hours, i;//s1, node14 hours = 0; //s25 i = 0; //s36 while (i < numSession) //s4, node27 {8 if (session[i].status == EXTRA) //s5, node39 {10 hours = hours + session[i].duration; //s6, node411 }12 else 13 {14 hours = hours //s8, node 5 15 }16 i++; //s9, node617 }18 return hours; //s10, node719}