Transcript
Page 1: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation
Page 2: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

White-Box Testing White-Box Testing

Control flow graph (CFG)Flow Graph NotationData Flow TestingMutation Testing

Advantages Of White Box Testing Disadvantages of white box testing

Page 3: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Uses the control structure part of component-level design to derive the test cases

These test cases◦ Guarantee that all independent paths within a module

have been exercised at least once◦ Exercise all logical decisions on their true and false

sides◦ Execute all loops at their boundaries and within their

operational bounds◦ Exercise internal data structures to ensure their validity

“Bugs lurk in corners and congregate at boundaries” BACK

Page 4: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

There exist several popular white-box testing methodologies:control flow graph:◦ Statement coverage◦ Branch coverage◦ Path coverageData flow based testing:◦ Loop testing◦ Nested Loops ◦ Concatenated Loops ◦ Unstructured Loopsmutation testing:

BACK

Page 5: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

A control flow graph (CFG) describes: ◦ the sequence in which different instructions of a

program get executed. ◦ the way control flows through the program.

Page 6: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Number all the statements of a program. Numbered statements:

◦ represent nodes of the control flow graph. An edge from one node to another node exists:

◦ if execution of the statement representing the first node can result in transfer of control to the other node.

Page 7: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

int f1(int x,int y){ 1. while (x != y){2. if (x>y) then 3. x=x-y;4. else y=y-x;5. }6. return x; }

Page 8: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

1

2

3 4

5

6

Page 9: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Statement coverage methodology:◦ design test cases so that◦ every statement in a program is executed at least

once. The principal idea:

◦ unless a statement is executed, ◦ we have no way of knowing if an error exists in that

statement

Page 10: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Based on the observation:◦ an error in a program can not be discovered◦ unless the part of the program containing the error is

executed. Observing that a statement behaves properly for one input

value:◦ no guarantee that it will behave correctly for all input

values

Page 11: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

int f1(int x, int y){ 1 while (x != y){ 2 if (x>y) then 3 x=x-y; 4 else y=y-x; 5 } 6 return x; }

NOTE:- By choosing the test set {(x=3,y=3),(x=4,y=3), (x=3,y=4)}◦ all statements are executed at least once.

Page 12: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Test cases are designed such that:◦ different branch conditions

given true and false values in turn. Similar to code coverage, but stronger Test every branch in all possible directions If statements

◦ test both positive and negative directions Switch statements

◦ test every branch◦ If no default case, test a value that doesn't match any case

Loop statements◦ test for both 0 and > 0 iterations

Page 13: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

White-box testing technique proposed by Tom McCabe Enables the test case designer to derive a logical

complexity measure of a procedural design Uses this measure as a guide for defining a basis set of

execution paths Test cases derived to exercise the basis set are guaranteed

to execute every statement in the program at least one time during testing

Page 14: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

A circle in a graph represents a node, which stands for a sequence of one or more procedural statements

A node containing a simple conditional expression is referred to as a predicate node◦ Each compound condition in a conditional expression

containing one or more Boolean operators (e.g., and, or) is represented by a separate predicate node

◦ A predicate node has two edges leading out from it (True and False)

An edge, or a link, is a an arrow representing flow of control in a specific direction◦ An edge must start and terminate at a node◦ An edge does not intersect or cross over another edge

Areas bounded by a set of edges and nodes are called regions

Page 15: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

15

1

2

0

3

4

5

6

7 8

9

1011

1

2

3

4 6

7 8 5

9

1011

R1

R2

R3

R4

FLOW GRAPH

0

Page 16: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Defined as a path through the program from the start node until the end node that introduces at least one new set of processing statements

Must move along at least one edge that has not been traversed before by a previous path

Basis set for flow graph on previous slide◦ Path 1: 0-1-11◦ Path 2: 0-1-2-3-4-5-10-1-11◦ Path 3: 0-1-2-3-6-8-9-10-1-11◦ Path 4: 0-1-2-3-6-7-9-10-1-11

The number of paths in the basis set is determined by the cyclomatic complexity

Page 17: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Provides a quantitative measure of the logical complexity of a program Defines the number of independent paths in the basis set and the number of

tests that must be conducted to ensure all statements have been executed at least once

Can be computed three ways◦ The number of regions◦ V(G) = E–N+2, where E is the number of edges and N is the number of

nodes in graph G◦ V(G) = P+1,where P is the number of predicate nodes

Results in the following equations for the example flow graph◦ Number of regions = 4◦ V(G) = 14 edges – 12 nodes + 2 = 4◦ V(G) = 3 predicate nodes + 1 = 4

Page 18: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Using the design or code as a foundation, draw a corresponding flow graph

Determine the cyclomatic complexity of the resultant flow graph

Determine a basis set of linearly independent paths Prepare test cases that will force execution of each path in

the basis set

Page 19: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

1 int functionY(void) 2 { 3 int x = 0; 4 int y = 19; 5 A: x++; 6 if (x > 999) 7 goto D; 8 if (x % 11 == 0) 9 goto B;10 else goto A;

11 B: if (x % y == 0) 12 goto C;13 else goto A;

14 C: printf("%d\n", x);15 goto A;

16 D: printf("End of list\n");17 return 0;18 }

3

4

5

6

7

16

17

8

9

11

12

14

15

13

10

BACK

Page 20: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

The techniques discussed so far have all been based on "control flow"

we can also design test cases based on "data flow“(how data flows through the code)

Some statements "define" a variable’s value (“variable definition”)

◦ Variable declarations with initial values◦ Assignments◦ Incoming parameter values

Some statements "use" variable’s value (“variable use”)◦ Expressions on right side of assignment◦ Boolean condition expressions

Page 21: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

A white-box testing technique that focuses exclusively on the validity of loop constructs

Four different classes of loops exist◦ Simple loops◦ Nested loops◦ Concatenated loops◦ Unstructured loops

Testing occurs by varying the loop boundary values◦ Examples:

for (i = 0; i < MAX_INDEX; i++)while (currentTemp >=

MINIMUM_TEMPERATURE)

Page 22: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Skip the loop entirely Only one pass through the loop Two passes through the loop m passes through the loop, where m < n n –1, n, n + 1 passes through the loop

‘n’ is the maximum number of allowable passes through the loop

Page 23: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Start at the innermost loop; set all other loops to minimum values

Conduct simple loop tests for the innermost loop while holding the outer loops at their minimum iteration parameter values; add other tests for out-of-range or excluded values

Work outward, conducting tests for the next loop, but keeping all other outer loops at minimum values and other nested loops to “typical” values

Continue until all loops have been tested

Page 24: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

For independent loops, Concatenated Loops means combination of more than one loop

In concatenated loops , testing depends upon interdependence among loops

If loops are not interdependence, then they should be tested in the someway as nested loops

Page 25: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Redesign the code to reflect the use of structured programming practices

Depending on the resultant design, apply testing for simple loops, nested loops, or concatenated loops

BACK

Page 26: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

The software is first tested:◦ using an initial testing method based on white-box

strategies. After the initial testing is complete,

◦ mutation testing is taken up. The idea behind mutation testing:

◦ make a few arbitrary small changes to a program at a time.

Page 27: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Each time the program is changed, ◦ it is called a mutated program ◦ the change is called a mutant.

A mutated program:◦ tested against the full test suite of the program.

If there exists at least one test case in the test suite for which:◦ a mutant gives an incorrect result, then the mutant is said to

be dead.

Page 28: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

If a mutant remains alive: ◦ even after all test cases have been exhausted, the test

suite is enhanced to kill the mutant. The process of generation and killing of mutants: can be automated by predefining a set of primitive changes

that can be applied to the program. The primitive changes can be:

◦ altering an arithmetic operator, ◦ changing the value of a constant, ◦ changing a data type, etc.

BACK

Page 29: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Testing can be commenced at an earlier stage. One need not wait for the GUI to be available.

Testing is more thorough, with the possibility of covering most paths.

BACK

Page 30: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

Developers often test with the intent to prove that the code works rather than proving that it doesn't work

Developers tend to skip the more sophisticated types of white box tests (e.g., condition testing, data flow testing, loop testing, etc.), relying mostly on code coverage◦ And developers also tend to overestimate the level of code

coverage White box testing focuses on testing the code that's there. If

something is missing, white box testing might not help you. There are many kinds of errors that white box testing won't find

◦ Timing and concurrency bugs◦ Volume and load limitations◦ Efficiency problems◦ Usability problems BACK

Page 31: White-Box Testing White-Box Testing  White-Box Testing White-Box Testing  Control flow graph (CFG) Control flow graph (CFG)  Flow Graph Notation

BACK TO INDEX