33
CONTROL FLOW TESTING UNIT - 3 1 Prepared By: Ravi J Khimani, CSE Department, SLTIET, Rajkot

Unit 3 Control Flow Testing

Embed Size (px)

Citation preview

Page 1: Unit 3   Control Flow Testing

1

CONTROL FLOW TESTINGUNIT - 3

Prepared By: Ravi J Khimani, CSE Department, SLTIET, Rajkot

Page 2: Unit 3   Control Flow Testing

2

CONCEPTS Two kinds of Basic Statements in Program

Assignment Statements Conditional Statements

Conditional Statements alters the default sequential control flow of program.

A program unit must be having a proper entry-point and exit-point, single or multiple.

Sequence of instruction from Entry-Point to Exit-Point is called Path.

Page 3: Unit 3   Control Flow Testing

3

CONCEPTS A specific input value causes a specific path

to be executed. That performs desired operations to produce

expected output. More execution of higher number of paths, at

higher cost, may not be effective to relieve defaults.

Control Flow Testing is a kind of Structural Testing which is performed by programmer to test code written by them.

Page 4: Unit 3   Control Flow Testing

4

GENERATE TEST INPUT DATA FOR CFT

Page 5: Unit 3   Control Flow Testing

5

ACTIVITIES IN GENERATE TEST INPUT DATA Over all idea of generation test input data is

to perform control flow testing. Those activities performed and intermediate

results are produced. Input: Source Code & Set of Path Selection

Criteria. Generation of a Control Flow Graph:

aim to visualize all possible paths in program unit. Graphical Representation of execution.

Page 6: Unit 3   Control Flow Testing

6

ACTIVITIES IN GENERATE TEST INPUT DATA Selection of Paths:

Paths are selected from CFG to satisfy Path Selection Criteria.

Generation of a Test Input Data: A Path can be executed if and only if input to program

unit cause all conditional statements to true or false as per CFG.

Such path is called Feasible Path. Otherwise it’s known as Infeasible Path.

Page 7: Unit 3   Control Flow Testing

7

ACTIVITIES IN GENERATE TEST INPUT DATA Feasibility Test of Path:

Idea behind it to check the path is to meet the path selection criteria.

If some path founds to be infeasible, then new paths are selected to be feasible.

Page 8: Unit 3   Control Flow Testing

8

CONTROL FLOW GRAPH A CFG is graphical representation of a program. Three symbols are used.

Page 9: Unit 3   Control Flow Testing

9

Page 10: Unit 3   Control Flow Testing

10

PATH REPRESENTATION

Page 11: Unit 3   Control Flow Testing

11

PATH SELECTION CRITERIA A Program Unit with small number of paths,

executing all paths may desirable and achievable.

But if large number of paths, then executing all path may not be practical.

What paths do I select for testing? it is more productive for programmers to

select a small number of program paths in an effort to reveal defects

Page 12: Unit 3   Control Flow Testing

12

ADVANTAGES OF PATH SELECTION Following, advantages of selecting paths

based on defined criteria: The programmer needs to observe the outcome

of executing each program construct. do not generate test inputs which execute the

same path repeatedly. It’s a waste of resources. If same path updates state of program, then

repeat execution of same path is not identical. Programmer can know the program features that

have been tested and those not tested

Page 13: Unit 3   Control Flow Testing

13

TECHNIQUES FOR PATH SELECTION All-Path coverage criteria

If all-path are selected in CFG, then one can detect all faults.

Except those due to missing path error. Program may contain infinite number of paths. So, if all paths are selected to perform testing,

then all-path selection criteria has been satisfied.

Page 14: Unit 3   Control Flow Testing

14

FOR EXAMPLE - ALL-PATH COVERAGE CRITERIA

Page 15: Unit 3   Control Flow Testing

15

CFGFOR

OPENFILES()FUNCTION

Page 16: Unit 3   Control Flow Testing

16

INPUT DOMAIN AND PATHS

Page 17: Unit 3   Control Flow Testing

17

TECHNIQUES FOR PATH SELECTION [CONT…] Statement Coverage Criteria

Refers to the individual program statement and measure the outcome.

100% achieved if all statements are executed. Its weakest coverage criteria. All program statements must be represent in

CFG with proper representation. So, basic problem is to select few feasible path

for covering all nodes in CFG. So, path length should be longer in increasingly

manner.

Page 18: Unit 3   Control Flow Testing

18

TECHNIQUES FOR PATH SELECTION [CONT…] Branch Coverage Criteria

Each node in CFG may have one or two branches. Covering branch means selecting path that

includes that branch. Complete branch coverage means selecting a

number of paths such a way that all possible branches must be included in those path.

Page 19: Unit 3   Control Flow Testing

19

TECHNIQUES FOR PATH SELECTION [CONT…]

Predicate Coverage Criteria Includes logic

check inside program, that covers all statements and branch coverage criteria.

Page 20: Unit 3   Control Flow Testing

20

TECHNIQUES FOR PATH SELECTION [CONT…]

So need to design test cases that covers all the possible conditions (logic).

The False branch of node 5 (Figure 4.9a) is executed under exactly one condition, namely, when OB1 = False, OB2 = False, and OB3 = False, whereas the true branch executes under seven conditions.

Page 21: Unit 3   Control Flow Testing

21

TECHNIQUES FOR PATH SELECTION [CONT…] If all possible combinations of truth values of

the conditions affecting a selected path have been explored under some tests, then we say that predicate coverage has been achieved.

For Example, The path taking the true branch of node 5 in Figure 4.9a must be executed for all seven possible combinations of truth values of OB1, OB2, and OB3 which result in OB = True.

Page 22: Unit 3   Control Flow Testing

22

GENERATING TEST INPUT After having an identified path, main

question is how to select input values? Such that, when program is executed with

such input values, the selected path gets executed.

So, it needs to identify input to force path execution.

Page 23: Unit 3   Control Flow Testing

23

GENERATING TEST INPUT For that some terms need to go through, 1. Input Vector

Collection of all data entities Fixed prior entering to routine / program. Like, input arguments, global variables, files,

network connections, timers, etc… For example, input vector for OPENFILE() function

is presence or absence of file1, file2, file3 and so on.

Page 24: Unit 3   Control Flow Testing

24

GENERATING TEST INPUT 2. Predicate

It’s a logical function evaluated at decision point. In this figure, OB is a predicate at decision point

Page 25: Unit 3   Control Flow Testing

25

GENERATING TEST INPUT 3. Path Predicate

It’s a set of predicates associated with the path.

Page 26: Unit 3   Control Flow Testing

26

GENERATING TEST INPUT 4. Predicate Interpretation

Predicate interpretation is defined as the process of symbolically substituting operations along a path in order to express the predicates solely in terms of the input vector and a constant vector.

Means, there is no role play of local variables inside functions because they are not visible to outside functions.

Those local variables can be easily substituted by the elements of input vector using symbolic substitution.

Page 27: Unit 3   Control Flow Testing

27

GENERATING TEST INPUT

Page 28: Unit 3   Control Flow Testing

28

GENERATING TEST INPUT 5. Path Predicate Expression

An interpreted path predicate is called a path predicate expression with following properties.

composed of input vector and constant vector set of constraints composed from input vector Forcing input values can be generated from

constraints in path predicate expression. If set of constraint can not be solved, then selected

path can not be executed. An infeasible path is not responsible for path predicate

expression, that dissatisfied. infeasibility of path forces to choose other path which

meet proper criteria.

Page 29: Unit 3   Control Flow Testing

29

GENERATING TEST INPUT

Page 30: Unit 3   Control Flow Testing

30

GENERATING TEST INPUT 6. Generating Input Data from PPE

The respective Path Predicate Expression must be solved in order to generate input data which can force a program to execute a selected path.

Page 31: Unit 3   Control Flow Testing

31

COINCIDENTAL CORRECTNESS In spite of the fault available in the code,

some test data produces the correct result, that’s known as Coincidental Correctness.

For Example,

Produces correct result in CFG at slide number 9

Page 32: Unit 3   Control Flow Testing

CONTAIN INFEASIBLE PATH A CFG may contain number of paths, shorter

or longer. Not practical to execute or analyze all paths. So, define strategy like,

Select as many as sort paths which are feasible Choose longer path to achieve coverage of

statements, predicates and branches. Reduce number of infeasible paths through

language design, program design, program transformations.

Page 33: Unit 3   Control Flow Testing

CONTAIN INFEASIBLE PATH Bertoline and Marre,

gave an algorithm which generate set of feasible paths.

Based on idea, Reduced Flow Graph, called ddgraph.

Yates & Malevries, Suggests a strategy to select a path with

minimum number of predicates.