Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

Module-3 ST (Part-2) - Path & Data Flow Testing - T1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Module-3 ST (Part-2) - Path & Data Flow Testing - T1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 96

MODULE -3

PATH TESTING
Program Graphs

• program graph is a directed graph in which


nodes are statement fragments, and edges
represent flow of control.

• If i and j are nodes in the program graph,


an edge exists from node i to node j if and
only if the statement fragment corresponding to
node j can be executed immediately after the
statement fragment corresponding to node i.
Style Choices for Program Graphs
Style Choices for Program Graphs
Style Choices for Program Graphs
• Decide 🡪 nonexecutable statements such as
variable and type declarations (included ?)
• Nodes 4 -to- 8 are a sequence.
• nodes 9 -to- 12 are an if–then–else construct.
• nodes 13 -to- 22 are nested if–then–else
constructs.
• Nodes 4 and 23 are the program source and
sink nodes (single entry, single-exit criteria).
• No loops exist, so this is a directed acyclic
graph.
• The importance of the program graph is that
program executions correspond to paths from the
source to the sink nodes.

• Test cases force the execution of some such


program path.

• There are detractors of path-based testing.

• detractors use to show the (practical) impossibility


of completely testing even simple programs.
DD-Paths
• The best-known form of code-based testing is
based on a construct known as a Decision-to-
Decision path (DD-path).

• The DD-path refers to a sequence of


statements that,
– begins with the “outway” of a decision statement,
– ends with the “inway” of the next decision
statement
– No internal branches occur in such a sequence.
• Cases 1 and 2 establish the unique source and
sink nodes.

• Case 3 deals with complex nodes; it assures


that no node is contained in more than one
DD-path.

• Case 4 is needed for “short branches”; it also


preserves the one-fragment, one DD-path
principle.
• Case 5 is the “normal case,” in which a DD-
path is a single entry, single-exit sequence of
nodes (a chain).

• The “maximal” part of the case 5 definition is


used to determine the final node of a normal
(nontrivial) chain.
DD-paths defn.

Given a program written in an imperative


language, its DD-path graph is the directed
graph in which nodes are DD-paths of its
program graph, and edges represent control
flow between successor DD-paths.
NODES D-D PATH CASE Defn
Basis Path Testing
• We define a basis in terms of a structure called
a “vector space”

• which is a set of elements (called vectors)

• as well as operations that correspond to


multiplication and addition defined for the
vectors.
Basis Path Testing…
• We can define several vector space and all
vector spaces have a basis.

• The basis of a vector space is a set of vectors


that are independent of each other and “span”
the entire vector space in the sense that any
other vector in the space can be expressed in
terms of the basis vectors.
Basis Path Testing…
• if we can view a program as a vector space,
then the basis for such a space would be a very
interesting set of elements to test.

• If the basis is okay, we could hope that


everything that can be expressed in terms of
the basis is also okay.
McCabe’s Basis Path Method

• McCabe based his view of testing on a major


result from graph theory, which states that,

The Cyclomatic number of a strongly


connected graph is the number of linearly
independent circuits in the graph.
McCabe’s Basis Path Method…

• We can always create a strongly connected


graph by adding an edge from the (every) sink
node to the (every) source node.
McCabe’s Basis Path Method…

Formula for Cyclomatic complexity:

V(G) = e – n + 2p

e is the number of edges,


n is the number of nodes, and
p is the number of connected regions

Since p is usually 1, adding the extra edge means


we move from 2p to p.
McCabe’s Basis Path Method…

The number of linearly independent paths from the


source node to the sink node of the graph on the left:
McCabe’s Basis Path Method…

The number of linearly independent circuits of


the graph on the right side of the graph:
McCabe’s Basis Path Method…

• The Cyclomatic complexity of the strongly


connected graph is 5.

• thus, there are five linearly independent


circuits.

• If we now delete the added edge from node G


to node A, these five circuits become five
linearly independent paths from node A to
node G.
McCabe’s Basis Path Method…

Here, we identify paths as sequences of nodes:


McCabe’s Basis Path Method…

Table shows the edges traversed by each path, and also the
number of times an edge is traversed:
McCabe’s Basis Path Method…

We can force this to begin to look like a vector


space by defining notions of addition and
scalar multiplication:

• path addition is simply one path followed by


another path,
• Multiplication corresponds to repetitions of a
path.
McCabe’s Basis Path Method…

His illustration of the basis part of this


framework is that:
• The path A,B,C,B, E,F,G is the basis sum
p2 + p3 – p1,

• The path A,B,C,B,C,B,C,G is the linear


combination 2p2 – p1.
McCabe’s Basis Path Method…

McCabe next develops an algorithmic procedure


(called the baseline method) to determine a set of
basis paths.
1. The method begins with the selection of a baseline
path, which should correspond to some “normal
case” program execution.

• This can be somewhat arbitrary.


• McCabe advises choosing a path with as many
decision nodes as possible.
McCabe’s Basis Path Method…

2. Next, the baseline path is retraced, and in


turn each decision is “flipped”; that is, when
a node of outdegree ≥ 2 is reached, a
different edge must be taken.

Eg: Here we follow McCabe’s example, in which he


first postulates the path through nodes
A, B, C, B, E, F, G as the baseline.
McCabe’s Basis Path Method…

• The first decision node


(outdegree ≥ 2) in this path is
node A;

• thus, for the next basis path, we


traverse edge 2 instead of edge 1.

• We get the path A, D, E, F, G,


where we retrace nodes E, F, G in
path 1 to be as minimally
different as possible.
Istriangle?

equilateral
scalen
Data Flow Testing
• Data flow testing refers to forms of structural
testing that focus on the points at which
variables receive values and the points at
which these values are used (or referenced).

• Most programs deliver functionality in terms of data.


• Variables that represent data somehow receive values,
and these values are used to compute values for other
variables.
Data Flow Testing…
• Early data flow analyses often centered on a
set of faults:

• A variable that is defined but never used (referenced)


• A variable that is used before it is defined
• A variable that is defined twice before it is used

These can be identified in static analysis: finding faults


in source code without executing it
Define / Use Testing…

• formalization of define/use testing was done in


the early 1980s.

• It presumes a program graph in which nodes are


statement fragments (a fragment may be an entire
statement) and programs that follow the structured
programming precepts.
Define / Use Testing…

• The following definitions refer to a Program P that has


a Program Graph G(P) and a set of Program Variables
V.
• The program graph G(P) is constructed with statement
fragments as nodes and edges that represent node
sequences.
• G(P) has a single-entry node and a single-exit node.
• We also disallow edges from a node to itself.
• The set of all paths in P is PATHS(P).
Define / Use Testing…

Defining Node:

• Node n ∈ G(P) is a defining node of the variable v ∈ V,


written as DEF(v, n), if and only if the value of variable
v is defined as the statement fragment corresponding to
node n.

• Input statements, assignment statements, loop control


statements, and procedure calls are all examples of
statements that are defining nodes.
Define / Use Testing…

usage node:

• Node n ∈ G(P) is a usage node of the variable v ∈ V,


written as USE(v, n), if and only if the value of the
variable v is used as the statement fragment
corresponding to node n.

• Output statements, assignment statements, conditional


statements, loop control statements, and procedure calls
are all examples of statements that are usage nodes.
Define / Use Testing…

predicate use / computation use :

• A usage node USE(v, n) is a predicate use (denoted as


P-use) if and only if the statement n is a predicate
statement; otherwise, USE(v, n) is a computation use
(denoted C-use).

• The nodes corresponding to predicate uses always have


an outdegree ≥ 2, and nodes corresponding to
computation uses always have an outdegree ≤ 1.
Define / Use Testing…

definition/use path:

• A definition/use path with respect to a variable v


(denoted du-path) is a path in PATHS(P) such that, for
some v ∈ V, there are define and usage nodes DEF(v,
m) and USE(v, n) such that m and n are the initial and
final nodes of the path.
Define / Use Testing…

definition-clear path :

• A definition-clear path with respect to a variable v


(denoted dc-path) is a definition/use path in
PATHS(P) with initial and final nodes DEF(v, m) and
USE(v, n) such that no other node in the path is a
defining node of v.
Define / Use Testing…

Example:

commission problem
Du-paths for Stocks:

We have DEF(stocks, 15) and USE(stocks, 17),

so the path <15, 17> is a du-path with respect to stocks.

No other defining nodes are used for stocks; therefore,


this path is also definition clear.
Du-paths for Locks :

we have
DEF(locks, 13), DEF(locks, 19),
USE(locks, 14), USE(locks, 16).
These yield four du-paths.
Define/Use Test Coverage Metrics

In the following definitions,


T is a set of paths in the program graph G(P) of a program P,
with the set V of variables.
Define/Use Test Coverage Metrics

In the following definitions,


T is a set of paths in the program graph G(P) of a program P,
with the set V of variables.
Define/Use Test Coverage Metrics

In the following definitions,


T is a set of paths in the program graph G(P) of a program P,
with the set V of variables.
Define/Use Test Coverage Metrics

In the following definitions,


T is a set of paths in the program graph G(P) of a program P,
with the set V of variables.
Define/Use Test Coverage Metrics

In the following definitions,


T is a set of paths in the program graph G(P) of a program P,
with the set V of variables.
Slice-Based Testing
Informally, a program slice is a set of program statements
that contributes to, or affects the value of, a variable at some
point in a program.

Defn:

Given a program P and a set V of variables in P, a slice on

the variable set V at statement n, written S(V, n), is the set of

all statement fragments in P that contribute to the values of

variables in V at node n.
There are two basic questions about program
slices:

• whether they are backward or forward


slices?

• whether they are static or dynamic?


• Backward slices refer to statement fragments
that contribute to the value of v at statement
n.

• Forward slices refer to all the program


statements that are affected by the value of v
and statement n.
• In a backward slice S(v, n), statement n is
nicely understood as a Use node of the
variable v, that is, Use(v, n).

• Forward slices are not as easily described, but


they certainly depend on predicate uses and
computation uses of the variable v.
static, backward slice

• Given a program P and a program graph G(P) in which


statements and statement fragments are numbered, and
a set V of variables in P, the static, backward slice on
the variable set V at statement fragment n, written
S(V, n), is the set of node numbers of all statement
fragments in P that contribute to the values of variables
in V at statement fragment n.
• The idea of program slicing is to separate a
program into components that have some
useful (functional) meaning.

• Another refinement is whether or not a


program slice is executable.
• If statement fragment n is a defining node for
v, then n is included in the slice.

• If statement fragment n is a usage node for v,


then n is not included in the slice.

• If a statement is both a defining and a usage


node, then it is included in the slice.
• In a Static Slice, P-uses and C-uses of other
variables (not the v in the slice set V ) are included
to the extent that their execution affects the value of
the variable v.

• As a guideline, if the value of v is the same whether


a statement fragment is included or excluded,
exclude the statement fragment.

• O-use, L-use, and I-use nodes are excluded from


slices.
Example
The commission problem

• only include nodes corresponding to


executable statement fragments.

• There are 42 “interesting” static backward


slices in our example.
The first six slices are the simplest—they are the nodes
where variables are initialized.
Slices 7 through 17 focus on the sentinel controlled
while loop in which the totals for locks,
stocks, and barrels are accumulated.
• Slices 18, 19, and 20 are output statements, and none
of the variables is defined.
Hence, the corresponding statements are not
included in these slices.
Slices 21 through 30 deal with the calculation of the
variable sales.

S30: S(sales, 27) = S23 ∪ S26 ∪ S29 ∪ {27}.


• Slices 31 through 36 are identical.

Slice S31 is an O-use of sales; the others are all C-


uses.

Since none of these changes the value of sales


defined at S30, we only show one set of statement
fragment numbers here.
• The last seven slices deal with the calculation of
commission from the value of sales.
• it is also helpful to see how slices are composed of
sets of previous slices.
• Several of the connections in the Figure are
double-headed arrows 🡨🡪 indicating set
equivalence.
• (if A ⊆ B and B ⊆ A, then A = B.)

• We can clean up the Figure by removing these,


and thereby get a better lattice.
Style and Technique

1. Never make a slice S(V, n) for which


variables v of V do not appear in statement
fragment n.

2. Make slices on one variable.

3. Make slices for all A-def nodes.


Style and Technique…

4. There is not much reason to make slices on


variables that occur in output statements.

5. Make slices for P-use nodes.

6. Consider making slices compilable.


Slice Splicing
• The commission program can be split into four slices.

• It also illustrates the basis for program comprehension


needed in software maintenance.

• Slices allow the maintenance programmer to focus on


the issues at hand and avoid the extraneous
information that would be in du-paths.
Slice 1 contains the input while
loop controlled by the locks variable.
Slice 2 use the loop to get input values for stocks
Slice 3 use the loop to get input values for barrel
Slices 1, 2, and 3 each culminate in a value of sales, which is the
starting point for Slice 4, which computes the commission bases
on the value of sales.
Program Slicing Tools

You might also like