0% found this document useful (0 votes)
5 views

Graphs Structural Coverage

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

Graphs Structural Coverage

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

Structural Graph Coverage Criteria

Meenakshi D’Souza

International Institute of Information Technology


Bangalore.
Graph coverage criteria: Overview

We look at graphs as structures and look at the following two


coverage criteria over graphs.
Structural coverage criteria.
Data flow coverage criteria.
Later, we consider software artifacts (code, design elements
and requirements) modelled as graphs and see how these
coverage criteria apply to them.
Focus of this lecture: Structural coverage criteria.
Structural coverage criteria over graphs

Node/vertex coverage.
Edge coverage.
Edge pair coverage.
Path coverage
Complete path coverage.
Prime path coverage.
Complete round trip coverage.
Simple round trip coverage.
Node coverage

Node coverage requires that the test cases visit each node in
the graph once.
Node Coverage: Test set T satisfies node coverage on graph
G iff for every syntactically reachable node n ∈ G , there is
some path p in path(T ) such that p visits n.
Test requirement (TR) contains each reachable node in G .
Edge coverage

Edge Coverage: TR contains each reachable path of length up


to 1, inclusive, in G .
Edge coverage is slightly stronger than node coverage.
Why “length up to 1” ?
It allows edge coverage for graphs with one node and no
edges.
Allowing length up to 1 allows edge coverage to subsume
node coverage.
Node and edge coverage: Example

Node coverage: TR = {1, 2, 3}, test path = [1, 2, 3].


Edge coverage: TR = {(1, 2), (1, 3), (2, 3)}, test paths =
{[1, 2, 3], [1, 3]}.
Node coverage and edge coverage are different only when there is
an edge in another sub-path between a pair of nodes, like the
above graph.
Covering Multiple Edges: Edge-Pair Coverage
Edge-Pair Coverage (EPC): TR contains each reachable path
of length up to 2, inclusive, in G .
Paths of length up to 2 correspond to pairs of edges.
Again, the phrase “length up to 2” ensures edge-pair coverage
holds for graphs with less than 2 edges.

1
5

2 4

6
3

TR = {[1, 4, 5], [2, 4, 5], [3, 4, 5], [1, 4, 6], [2, 4, 6], [3, 4, 6]}.
Test paths are the same as above.
Covering Multiple Edges, contd.

An extension of edge-pair coverage is to consider all paths.


Complete path coverage: TR contains all paths in G .
Unfortunately, this is can be an infeasible test requirement.
Also, it may not be a useful test requirement.
Specified path coverage: TR contains a set S of paths, where
S is specified by the user/tester.
Usually decided based on individual/team needs.
Coverage criteria seen so far: Another example

Node coverage: TR = {1, 2, 3, 4, 5, 6, 7}, Test


paths: {[1, 2, 3, 4, 7], [1, 3, 5, 6, 5, 7]}.
1
Edge coverage: TR =
{(1, 2), (1, 3), (2, 3), (3, 4), (4, 7), (3, 5), (5, 6), (6, 5), (5, 7)}
2
Test paths: {[1, 2, 3, 4, 7], [1, 3, 5, 6, 5, 7]}.

3 Edge-pair coverage: TR =
{[1, 2, 3], [1, 3, 4], [1, 3, 5], [2, 3, 4], [2, 3, 5], [3, 4, 7], . . .},
4 5 Test paths:
6
{[1, 2, 3, 4, 7], [1, 2, 3, 5, 7], [1, 3, 4, 7], [1, 3, 5, 6, 5, 6, 5, 7]}.
7
Complete path coverage: TR =
{[1, 2, 3, 4, 7], [1, 2, 3, 5, 7], [1, 2, 3, 5, 6, 5, 7], . . .}.
Complete and Specified Path Coverage

If a graph contains a loop, it has an infinite number of paths


and hence complete path coverage is infeasible.
What will be a good notion of specified path coverage in the
presence of loops?
Loops have boundary conditions and repeated executions.
Effective test cases will not execute the loop for every
iteration.
Ideally, we need to have test cases that cover the loop:
Execute the loop at its boundary conditions— skip the loop
execution.
Execute the loop once for normal iterations.
The notion of prime paths came into existance for working
with loops.
Prime Paths in Graphs

A path from node ni to nj is simple if no node appears more


than once, except possibly the first and last node.
No internal loops.
A loop is a simple path.
A prime path is a simple path that does not appear as a
proper subpath of any other simple path.
Simple paths and prime paths: Example

2 3

Simple paths: [1,2,4,1], [1,3,4,1], [2,4,1,2], [2,4,1,3], [3,4,1,2],


[3,4,1,3], [4,1,2,4], [4,1,3,4], [1,2,4], [1,3,4], [2,4,1], [3,4,1],
[4,1,2], [4,1,3], [1,2], [1,3], [2,4], [3,4], [4,1], [1], [2], [3], [4]
Prime paths: [2,4,1,2], [2,4,1,3], [1,3,4,1], [1,2,4,1], [3,4,1,2],
[4,1,3,4], [4,1,2,4], [3,4,1,3]
Prime path coverage

Prime path coverage: TR contains each prime path in G .


Ensures that loops are skipped as well as executed.
By touring all paths of length 0 and 1, it subsumes node and
edge coverage.
May or may not subsume edge-pair coverage.
Prime path coverage vs. edge-pair coverage

In graphs where there are self loops, edge-pair coverage


requires the self loop to be visited.
For e.g., in the above graph, TR for edge-pair coverage will
be {[1, 2, 3], [1, 2, 2], [2, 2, 3], [2, 2, 2]}.
Some of these are prime paths/simple paths.
TR for prime path coverage for the above example is
{1, 2, 3], [2, 2]}.
Prime path coverage and loops in graphs

Prime paths capture the notion of covering a loop well.

There are nine prime paths.


2
They correspond to
3
1,3,5,7 : Skipping the loop,
1,3,5,6 : Executing the loop once, and
4 5 6,5,6 : Executing the loop more than once.
7 6
Implementing test requirements for prime path coverage

Prime paths, by definition, do not have internal loops.


In many cases, it might be impossible to meet the test
requirement of prime path coverage without internal loops.
That is, test paths that meet prime path coverage TR need to
have internal loops to make prime path coverage feasible.

1 2 3 4 5

6
Touring, side trips and detours

Tour: A test path p tours sub-path q if q is a sub-path of p.


Tour with side trips: A test path p tours sub-path q with
sidetrips iff every edge in q is also in p in the same order.
The tour can include a sidetrip, as long as it comes back to
the same node.
Tour with detours: A test path p tours sub-path q with
detours iff every node in q is also in p in the same order.
The tour can include a detour from node n, as long as it
comes back to the prime path at a successor of n.
Touring, side trips and detours: Example

1 2 3 4 5

Touring the prime path without side trips and detours

1 2 3 4 5

6
Touring the prime path with a side trip

1 2 3 4 5

Touring the prime path with a detour


Infeasible test requirements

Some test requirements related to graph structural coverage


can be infeasible.
It is undecidable to check if many structural coverage
requirements are feasible or not.
Typically, when side trips are not allowed, many structural
coverage criteria have infeasible test requirements.
However, always allowing side trips weakens the test criteria.
Best Effort Touring: Satisfy as many test requirements as
possible without sidetrips. Allow sidetrips to try to satisfy
remaining test requirements.
Round trips

Round trip path: A prime path that starts and ends at the
same node.
Simple round trip coverage: TR contains at least one round
trip path for each reachable node in G that begins and ends in
a round trip path.
Complete round trip coverage: TR contains all round trip
paths for each reachable node in G .
The above two criteria omit nodes and edges that are not in
round trips.
Hence, they do not subsume edge-pair, edge or node coverage.
Structural Coverage Criteria Subsumption

Complete Path Coverage

Prime Path Coverage

Edge Pair Coverage Complete Round Trip Coverage

Edge Coverage Simple Round Trip Coverage

Node Coverage
Credits

Part of the material used in these slides are derived from the
presentations of the book Introduction to Software Testing, by
Paul Ammann and Jeff Offutt.

You might also like