29
White Box Testing

White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

Embed Size (px)

Citation preview

Page 1: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

White Box Testing

Page 2: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 2

• White Box Testing or Glass Box Testing

– Test case design method that uses the control structure of the procedural design to derive test cases

• SW Engineer can derive test cases that

– guarantee that all independent paths within a module have been exercised at least once

– exercise all logical decisions on their true and false bounds

– execute all loops at their boundaries and within their operational bounds

– exercise internal data structures to assure their validity

Introduction White Box testing

Page 3: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 3

Basis Path/Control Structure Testing

• Proposed by Tom McCabe

• The basis path method enables the test case designer to derive a logical complexity measure of a procedural design and use this measure as a guide for defining a basis set of execution paths

• Flow Graph Notation:

Sequence

If

While

Repeat - UntilCase

Page 4: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 4

Compound Logic

IF a or b

then procedure X

else procedure Y

endif

a

b

xxy

Predicate Node

Page 5: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 5

Cyclomatic Complexity ( V(G) )

• Cyclomatic Complexity

– software metric that provide a quantitative measure of the logical complexity of a program]

V(G) = E - N + 2

V(G) = 9 - 8 + 2 = 3

• The number of regions of the flow graph correspond to the cyclomatic complexity.

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

Page 6: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 6

Independent Path

• An independent path is any path through the program that introduces at least one new set of processing statements or a new condition

• An independent path must move along at least one edge that has not been traversed before the path is defined

1

2,3

7

4,5,69,108

11

12

13

path 1: 1-13

path 2: 1-2-3-7-8-11-12-1-13

path 3: 1-2-3-7-9-10-11-12-1-13

path 4: 1-2-3-4-5-6-12-1-13

Is the path

1-2-3-4-5-6-12-1-2-3-7-8-11-12-1-13

an independent path ?

Page 7: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 7

Deriving Test Cases

• Draw a corresponding flowgraph using the design or code as a foundation

• Determine the cyclomatic complexity of the resultant flow graph (V(g))

• Determine a basis set of linearly independent paths

• Prepare test cases that will force execution of each path in the basis set

– if we have 6 independent paths, then we should have at least 6 test cases. For each test cases, we should define

• the input conditions and

• the expected result.

Page 8: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 8

Graph Matrices

• Can automate derivation of flow graph and determination of a set of basis paths.

• Software tools to do this can use a graph matrix.

• Graph matrix:

is square with #sides equal to #nodes

Rows and columns correspond to the nodes

Entries correspond to the edges.

• Can associate a number with each edge entry.

• Use a value of 1 to calculate the cyclomatic complexity

For each row, sum column values and subtract 1.

Sum these totals and add 1.

Page 9: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 9

Some other interesting link weights:

Probability that a link (edge) will be executed

Processing time for traversal of a link

Memory required during traversal of a link

Resources required during traversal of a link

Page 10: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 10

Branch Testing

• Branch testing is the simplest condition testing strategy

• For a compound condition C, the true and false branches of C and every simple condition in C need to be executed at least once

Page 11: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

2c

• Program Coba;

• Var a , b : integer;

• Begin

• a := 5; {1}

• b := 8;

• if a > b then {2}

• a :=2 {3}

• else

• b := a; {4}

• end. {5}

9/18/2012 Rini/S2 LIKMI 11

1

2

3 4

5

R1

R2

Page 12: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

2D

• Program Coba;

• Var a , b : integer;

• Begin

• A := 5; (1)

• If a > 3 then (2)

• a := 2; (3)

• writeln(a); (4)

• end. (5)

9/18/2012 Rini/S2 LIKMI 12

Page 13: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

tes3

• Program Coba;

• var a : integer;

• begin

• a := 5; (1)

• while a < 10 do (2)

• Begin (3)

• a := a + 1; (4)

• end; (5)

• a := a + 10; (6)

• writeln; (7)

• end.

9/18/2012 Rini/S2 LIKMI 13

Page 14: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 14

Condition Testing (1)

• Condition Testing aims to exercise all logical conditions in a program module.

• Can Define

– Relational Expression (E1 op E2) : where E1 and E2 are arithmetic expression

– Simple Condition: Boolean variable or relational expression, possibly preceded by a NOT operator

– Compound condition: composed of two or more simple conditions, boolean operators and parentheses

– Boolean Expression: condition without relational expression

• Types of errors in a condition include the following

– boolean operator error (existence of incorrect/missing/extra boolean operator)

– boolean variable error

– boolean parenthesis error

– relational operator error

– arithmetic expression error

Page 15: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 15

Condition Testing (2)

• The condition testing method focuses on testing each condition in the program.

• Advantage of condition testing strategies

– measurement of test coverage of a condition is simple

– the test coverage of conditions in a program provides guidance for the generation of additional tests for the program

• Some condition testing strategies

– Branch Testing

– Domain Testing

– Branch and Relational Operator Testing - uses condition constraints

• Example 1: C1 = B1 & B2

– Where B1, B2 are boolean conditions

– condition constraint of form D1, D2 where D1 and D2 can be true (t) or false (f)

– The branch and relational operator test requires the constraint set { (t,t), (f,t), (t,f) } to be covered by the execution of C1

• coverage of the constraint set guarantees detection of relational operator errors

Page 16: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 16

Data Flow Testing

• Data Flow testing method select test paths of a program according to the locations of definitions and uses of variables in the program

• With Data flow testing

– each statement in a program is assigned a unique statement number and it assumes that each function doesn’t modify its parameters or global variables

• Defs( s ) = { x | statement S contains a definition of X }

• Use( s ) = { x | statement S contains a use of X }

• DU Chain (Definition - Use Chain) of variable X is of the form {X, S, S’}, where S, S’ are statement numbers, X is in Defs(S) and Defs(S’).

• Other possible chains are:

– DD (Definition-Definition Chain) - Should be avoided !! Why ??

– UU (Use-Use Chain) - common chain

– UD (Use-Definition Chain) - common chain

• One simple strategy is DU Testing Strategy.

– The strategy requires that every DU chain be covered at least once.

Page 17: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 17

Loop Testing

• Loop is fundamental to many algorithms.

• Loop can be defined as simple, concatenated, nested, and unstructured.

Simple Loops

Nested Loops

ConcatenatedLoops

UnstructuredLoops

Page 18: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 18

Loop Testing (2)

• To test:

Simple Loops of size n:

Skip loop entirely

Only one pass through loop

Two passes through loop

m passes through loop where m<n.

(n-1), n, and (n+1) passes through the loop.

Nested Loops

Start with inner loop. Set all other loops to minimum values.

Conduct simple loop testing on inner loop.

Work outwards

Continue until all loops tested.

Concatenated Loops

If independent loops, use simple loop testing.

If dependent, treat as nested loops.

Unstructured loops

Don't test - redesign.

Page 19: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

tes2c

Program Coba;

Var a , b : integer;

• Begin

– a := 5; (1)

– b := 8; (2)

• if a > b then (3)

– a := 2 (4)

• Else b := a; (5)

• end. (6)

9/18/2012 Rini/S2 LIKMI 19

1

2

3

4 5

6 R1

R2

1. Jumlah region = 2

2. V(G) = E-N+2

= 6- 6+2=2

3. p+1 = 1 + 1 = 2

4. Jalur independen :

I. 1- 2-3 -4-6

II. 1-2-3-5-6

Page 20: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

• Program Coba;

• Var a , b : integer;

• Begin

– A := 5; (1)

– If a > 3 then (2)

– a := 2; (3)

– writeln(a); (4)

• end. (5)

9/18/2012 Rini/S2 LIKMI 20

Page 21: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

tes3

• Program Coba;

• var a : integer;

• begin

a := 5; (1)

while a < 10 do (2)

Begin (3)

a := a + 1; (4)

end; (5)

a := a + 10; (6)

writeln; (7)

• end.

9/18/2012 Rini/S2 LIKMI 21

1

2

6

7

3

4

5

R1

R2

Page 22: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

tes4

• Program Coba;

• Var a : integer;

• Begin

• for a := 5 to 10 do (1)

• Begin (2)

• writeln(a); (3)

• end; (4)

• writeln; (5)

• end.

9/18/2012 Rini/S2 LIKMI 22

Page 23: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

• Program Coba;

• Var a : integer;

• Begin

• a := 5; (1)

• Repeat (2)

• a := a + 1; (3)

• until a > 10; (4)

• a := a + 20; (5)

• writeln; (6)

• end.

9/18/2012 Rini/S2 LIKMI 23

Page 24: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

7 • Program Coba;

• var a , b, c : integer;

• begin

• a := 5;

• b := 8;

• c := 4;

• if (a > b) or (a > c) then

• begin

• a := 2; ------------------

• end

• else

• begin

• if b = a then ---------------

• b := a

• else

• b := c;

• end;

• readln;;

• end. 9/18/2012 Rini/S2 LIKMI 24

(1)

(2,3)

(4)

(5)

(6)

(7)

(8)

Test case :

INPUT OUTPUT

1. a=4,b=2, c=1 a>b? T;a=2;b=2,c=1

2.a=5,b=8,c=4 a>b?F;a>c?T;a=2,b=8,c=4

3.a=3;b=3,c=5 a>b?F, a>c ? F, a=b?T; a=3, b=3,c=5

4. a=3,b=5,c=3 a>b?F, a>c ? F, a=b?F; a=3, b=5,c=5

Page 25: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

8

• Program Coba;

• var a : integer;

• begin

• a := 5; --- (1)

• while a < 10 do ---(2)

• begin

• if a > 5 then --- (3)

• writeln(a); --- (4)

• a := a + 1; --- (5)

• end; --- (6)

• a := a + 10; --- (7)

• writeln; --- (8)

• end. 9/18/2012 Rini/S2 LIKMI 25

Page 26: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

tes11

• Program Coba;

• Var a, b : integer;

• Begin

• Readln (a, b); …(1)

• Case a of …(2)

• 1 : if a > b then …(3)

• writeln(a); …(4)

• 2 : if a < b then …(5)

• writeln(b); …(6)

• end; …(7)

• writeln(a, b); …(8)

• end.

9/18/2012 Rini/S2 LIKMI 26

Page 27: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 27

Pseudo Code - Flow Chart

• Procedure Sort

Procedure Sort

1. do while not eof

2. Read Record

3. if record field 1 = 0

4. then process record

5. store in buffer;

6. increment counter

7. else if record field 2 = 0

8. then reset counter

9. else process record

10. store in file

11. endif

12. endif

13. enddo

1

3

7

11

12

2

4

59

8

610

• Flow Chart

Page 28: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

9/18/2012 Rini/S2 LIKMI 28

Flow Chart - Flow Graph

1

3

7

11

12

2

4

59

8

610

• Flow Chart

1

2,3

7

4,5,69,108

11

12

• Flow Graph

1 2 3

4 5

6 7

8 9

10

11 R1

R2 R3

R4

V(G) = 11-9 + 2 = 4

P+1=3+1 =4

Page 29: White Box Testing - Masalah ICT dan solusinya…ada disini! · • The basis path method enables the test case designer to derive a logical complexity measure of a procedural design

Bhn UAS/kuis

• Bab 9-10 & 15&17

• s.d whitebox

9/18/2012 Rini/S2 LIKMI 29