Upload
ravikhimani
View
682
Download
0
Embed Size (px)
Citation preview
1
CONTROL FLOW TESTINGUNIT - 3
Prepared By: Ravi J Khimani, CSE Department, SLTIET, Rajkot
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.
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.
4
GENERATE TEST INPUT DATA FOR CFT
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.
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.
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.
8
CONTROL FLOW GRAPH A CFG is graphical representation of a program. Three symbols are used.
9
10
PATH REPRESENTATION
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
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
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.
14
FOR EXAMPLE - ALL-PATH COVERAGE CRITERIA
15
CFGFOR
OPENFILES()FUNCTION
16
INPUT DOMAIN AND PATHS
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.
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.
19
TECHNIQUES FOR PATH SELECTION [CONT…]
Predicate Coverage Criteria Includes logic
check inside program, that covers all statements and branch coverage criteria.
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.
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.
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.
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.
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
25
GENERATING TEST INPUT 3. Path Predicate
It’s a set of predicates associated with the path.
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.
27
GENERATING TEST INPUT
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.
29
GENERATING TEST INPUT
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.
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
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.
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.