Presentation is loading. Please wait.

Presentation is loading. Please wait.

White-box Testing.

Similar presentations


Presentation on theme: "White-box Testing."— Presentation transcript:

1 White-box Testing

2 Contents Advantages Of White Box Testing
Control flow graph (CFG) Flow Graph Notation Data Flow Testing Mutation Testing Advantages Of White Box Testing  Disadvantages of white box testing

3 White-Box Testing 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

4 White-Box Testing There exist several popular white-box testing methodologies: control flow graph: Statement coverage Branch coverage Path coverage Data flow based testing: Loop testing Nested Loops Concatenated Loops Unstructured Loops mutation testing: BACK

5 Control flow graph (CFG)
A control flow graph (CFG) describes: the sequence in which different instructions of a program get executed. the way control flows through the program.

6 Steps to draw Control flow graph
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.

7 Example int f1(int x,int y){ while (x != y){ if (x>y) then x=x-y;
else y=y-x; } return x; }

8 1 2 3 4 5 6 Control Flow Graph

9 Statement Coverage 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

10 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

11 Example int f1(int x, int y){ 1 while (x != y){ 2 if (x>y) then
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.

12 Branch coverage 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

13 Basis Path Testing 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

14 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

15 Flow Graph Example R4 1 1 FLOW GRAPH 2 2 R3 3 3 6 4 6 4 R2 7 8 5 7 R1
R4 1 1 FLOW GRAPH 2 2 R3 3 3 6 4 6 4 R2 7 8 5 7 R1 8 5 9 9 11 10 11 10

16 Independent Program Paths
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: Path 2: Path 3: Path 4: The number of paths in the basis set is determined by the cyclomatic complexity

17 Cyclomatic Complexity
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

18 Deriving the Basis Set and Test Cases
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

19 A Second Flow Graph Example
3 4 1 int functionY(void) 2 { 3 int x = 0; 4 int y = 19; 5 A: x++; 6 if (x > 999) goto D; 8 if (x % 11 == 0) goto B; else goto A; 11 B: if (x % y == 0) goto C; else goto A; 14 C: printf("%d\n", x); goto A; 16 D: printf("End of list\n"); return 0; 18 } 5 6 8 7 10 9 16 11 17 13 12 14 BACK 15

20 Data Flow Testing 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

21 Loop Testing 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)

22 Testing of Simple Loops
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

23 Testing of Nested Loops
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

24 Testing of Concatenated Loops
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

25 Testing of Unstructured Loops
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

26 Mutation Testing 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.

27 Mutation Testing 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.

28 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

29 Advantages Of White Box Testing
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

30 Disadvantages of white box testing
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

31 THANKS BACK TO INDEX


Download ppt "White-box Testing."

Similar presentations


Ads by Google