32
CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

Embed Size (px)

Citation preview

Page 1: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 1

White-Box Testing

Based on Pressman Ch 17 (5th edition) or Ch 14 (6th edition)

Page 2: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

• Introduction• Overview of White-box testing • Basis path testing• Control structure testing

Ref. Video:http://www.youtube.com/watch?v=wLINA-Gj7eAhttp://www.youtube.com/watch?v=FXZ5Mxgxg8k&feature=relatedhttp://www.youtube.com/watch?v=RhlzjrGgrGU&feature=related

2

Agenda

Page 3: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

Internal and External Views

• Any engineered product (and most other things) can be tested in one of two ways: – Knowing the specified function that a product

has been designed to perform, tests can be conducted that demonstrate each function is fully operational while at the same time searching for errors in each function;

– Knowing the internal workings of a product, tests can be conducted to ensure that "all gears mesh," that is, internal operations are performed according to specifications and all internal components have been adequately exercised.

Page 4: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

Test Case Design

"Bugs lurk in corners

and congregate at

boundaries ..."

Boris Beizer

OBJECTIVE

CRITERIA

CONSTRAINT

to uncover errors

in a complete manner

with a minimum of effort and time

Page 5: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 5

What is a ‘Good’ Test?

• A good test has a high probability of finding an error.

• A good test is not redundant.

• A good test should be “best of breed”.

• A good test should be neither too simple nor too complex.

Page 6: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 6

Exhaustive Testing

• Executing a program with all possible combinations of inputs or values for program variables

Computer Dictionary Onlinehttp://www.computer-dictionary-online.org/exhaustive%20testing.htm?q=exhaustive

%20testing

Page 7: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 7

Exhaustive Testing

loop < 20 X

There are 10 possible paths! If we execute onetest per millisecond, it would take 3,170 years totest this program!!

14

Page 8: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 8

Selective Testing

loop < 20 X

Selected path

Page 9: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 9

White-Box Testing

our goal is to ensure that all statements and conditions have been executed at least once ...

Page 10: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 10

White-Box Testing (cont.)

• It is a test case design approach that uses the control structure (described as part of procedural design) to DERIVE test cases.

• We can derive test cases that: Guarantee that all independent paths within a module

have been exercised/covered 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.

Page 11: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 11

Why Cover?

Logic errors and incorrect assumptions

are inversely proportional to a path's

execution probability.

We often believe that a path is not

likely to be executed; in fact, the reality is

often counter intuitive.

Typographical errors are random; it's

likely that untested paths will contain

some.

Page 12: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

Cyclomatic Complexity

• A measure of the number of linearly independent paths through a program module

• Cyclomatic Complexity is a measure for the complexity of code related to the number of ways there are to traverse a piece of code. This determines the minimum number of inputs you need to test all ways to execute the program.

• A software metric that provides a quantitative measure of the logical complexity of a program.

Page 13: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 13

Cyclomatic Complexity

A number of industry studies have indicated that the higher V(G), the higher the probability of errors.

V(G)

modules

modules in this range are more error prone

Page 14: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 14

Basis Path Testing

• It is one of the main ‘white-box’ testing techniques.

• It 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.

• Test cases derived to exercise the basis set are guaranteed to execute every statement in the program at least one time during testing.

Page 15: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 15

Basis Path Testing - Steps

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

• Determine the cyclomatic complexity of the graph.

• Determine a basis set of linearly independent paths.

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

Page 16: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 16

Basis Path Testing – e.g.

First, we compute the cyclomatic complexity:the number of simple decisions + 1 or

the number of enclosed areas + 1

In this case, V(G) = 4

Page 17: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 17

Basis Path Testing e.g.Next, we derive the independent paths:

Since V(G) = 4,there are four paths

Path 1: 1,2,3,6,7,8Path 2: 1,2,3,5,7,8Path 3: 1,2,4,7,8Path 4: 1,2,4,7,2,4,...7,8

Finally, we derive testcases to exercise these paths.

1

2

34

5 6

7

8

Page 18: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 18

Basis Path Testing - Notes

You don't need a flow chart, but the picture will help when you trace program paths.

Count each simple logical test, compound tests count as 2 or more.

Basis path testing should be applied to critical modules.

Page 19: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

Flow Graph Notation

• Flow Graph or Program Graph

• The representation of control flow

• Depicts logical control flow.

Page 20: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

Flow Graph Notation (cont.)IfSe que nce

Until

Case

While

Page 21: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

Flowchart and Flow Graph

Page 22: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 22

Graph Matrices

• A graph matrix is a square matrix whose size (i.e., number of rows and columns) is equal to the number of nodes on a flow graph.

• Each row and column corresponds to an identified node, and matrix entries correspond to connections (an edge) between nodes.

• By adding a link weight to each matrix entry, the graph matrix can become a powerful tool for evaluating program control structure during testing.

Page 23: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

Graph Matrices – e.g.

1

2

3

45

a

b

c

d

e

f

g

Node

Connected toNode

1 2 3 4 5

1

2

3

4

5

a

b

c

d

e

f

g

Graph Matrix

Flow Graph

Page 24: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 24

Control Structure Testing

• The basis path testing is simple and effective, but it is not sufficient in itself.

• Control structure testing techniques broaden testing coverage and improve quality of white-box testing.

Page 25: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 25

Control Structure Testing

• Basis path testing

• Condition testing — exercises the logical conditions contained in a program module.

• Data flow testing — selects test paths of a program according to the locations of definitions and uses of variables in the program.

• Loop testing — focuses exclusively on the validity of loop constructs.

Page 26: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 26

Condition Testing – e.g.• A simple/basic condition is a Boolean variable or a

relational expression (e.g. m>n, x+5<= 2*y, etc)

• A compound (or multiple) condition is composed of two or more simple conditions, Boolean operators, and parentheses.

For example m>n AND x+5<=2*y, m>n OR x+5<=2*y, etc.

Page 27: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 27

Multiple Conditions - 1

Conditions:1 A > 52 B < 10

If (A > 5) and (B < 10) then S1 else S2;

1

2

S1S2

T

F

T

F

Page 28: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 28

Multiple Conditions - 2

If (A > 5) or (B < 10) then S1 else S2;

Conditions:1 A > 52 B < 10

1

2

S1

T

F

T

F

S2

Page 29: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 29

Loop Testing

Nested Loops

Concatenated Loops Unstructured

Loops

Simple loop

Page 30: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 30

Loop Testing: Simple Loops

Minimum conditions—Simple Loops

1. skip the loop entirely

2. only one pass through the loop

3. two passes through the loop

4. m passes through the loop m < n

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

where n is the maximum number of allowable passes

Page 31: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1 31

Loop Testing: Nested Loops

Start at the innermost loop. Set all outer loops to their minimum iteration parameter values.

Test the min+1, typical, max-1 and max for the innermost loop, while holding the outer loops at their minimum values.

Move out one loop and set it up as in step 2, holding all other loops at typical values. Continue this step until the outermost loop has been tested.

If the loops are independent of one another then treat each as a simple loop else* treat as nested loopsendif*

for example, the final loop counter value of loop 1 is used to initialize loop 2.

Nested Loops

Concatenated Loops

Page 32: CC20O7N Software Engineering 1 1 White-Box Testing Based on Pressman Ch 17 (5 th edition) or Ch 14 (6 th edition)

CC20O7N Software Engineering 1

SummarySummary

• Overview of White-box testing • Basis path testing• Other control structure testing