Whitebox Testing

# Whitebox Testing - The Basis Set as a Measure of Test Goodness

Created 3 years ago

Duration 0:07:42
413
Slide Content
1. ### Slide 1 - Whitebox Testing: The Basis Set as a Measure of Test Goodness

• Emerson Murphy-Hill
• Material Produced by NCSU Software Engineering Faculty.
2. ### Slide 2 - What Makes Tests Good?

• Black Box:
• Equivalence Class/Boundary Value Analysis
• Think diabolically
• White Box:
• Basis (Path) Set
• Coverage (discussed in next lecture)
3. ### Slide 3 - Basis Set

• Compute Cyclomatic number - V(G)
• This gives us an estimate of how many tests must be designed and executed to guarantee coverage
• The number of independent paths that must be tested to ensure that all statements have been executed at least once and every condition will have been executed on its true and false side!!
• An easy way to calculate cyclomatic complexity
• V(G) = P + 1
• (P = number of predicate nodes in a control flow graph)
4. ### Slide 4 - Control Flow Graph

• Pictorial representation of flow of control
• Rectangle: a sequence of processing steps (series of linear statements)
• Diamond: a logic conditional or predicate
5. ### Slide 5 - Control Flow Structures in CFGs

• T
• F
• for and while Loops
• T
• F
• do-while Loops
• T
• F
• if Statement
• T
• F
• if/else Statement
• e
• F
• if
• T
• T
• F
• predicate1 && predicate2
• if
• T
• e
• F
• F
• T
• predicate1 || predicate2
6. ### Slide 6 - StringAnalyzer Code

• public static int countDigits(String line, char min, char max) {
• int digitCount = 0;
• if (checkBounds(min, max)) {
• for (int i = 0; i < line.length(); i++) {
• char c = line.charAt(i);
• if (c >= min && c <= max) {
• digitCount++;
• }
• }
• } else {
• digitCount = -1;
• }
• return digitCount;
• }
7. ### Slide 7 - countDigits CFG

• public static int countDigits(String line, char min, char max) {
• int digitCount = 0;
• if (checkBounds(min, max)) {
• for (int i = 0; i < line.length(); i++) {
• char c = line.charAt(i);
• if (c >= min && c <= max) {
• digitCount++;
• }
• }
• } else {
• digitCount = -1;
• }
• return digitCount;
• }
• 1
• int digitCount = 0;
• 4
• char c = line.charAt(i);
• 7
• digitCount++;
• 8
• digitCount = -1;
• 9
• return digitCount;
• 2
• checkBounds(min,max)
• 3
• i < line.length()
• 5
• c >= min
• 6
• c <= max
• F
• F
• F
• F
• T
• T
• T
• T
8. ### Slide 8 - Basis Set - Decisions

• For if statements
• True path
• False path
• For loops
• Don’t go through the loop at all
• Go through the loop once
• Go through the loop twice (beyond the basis set)