Software White Box Testing – Cyclomatic Complexity

White Box testing types

• We have the following types for White box testing based on the technicalities
• Code Coverage Analysis (includes)
• Basis Path Testing
• Flow Graph Notation,
• Cyclomatic complexity,
• Control Structure Testing
• Conditions Testing,
• Data flow testing,
• Loop Testing.

Basis Path Testing
• This is a testing mechanism proposed by McCabe,
• The aim of this testing is to derive the logical complexity measure of a procedural design and use this information as a guide for defining a
basic set of execution paths.
• The resulting test cases will ensure that the basic set of paths will execute every statement at least once.

Flow Graph Notation
• It is a representation, using graph notation, of all paths that might be traversed
through a program during its execution,
• Each Node in the graph represents a basic block,
• Directed edges are used to represent jumps in the control flow,
• There should exist two blocks (Entry Block and Exit Block)
• Entry Block : through which control enters into the flow graph,
• Exit Block : through which all control flow leaves.

Flow Graph Notation : Example
• Consider the following code
0: (A) t0 = read_num
1: (A)ift0mod 2 ==0goto 4
2: (B) print t0 + ” is odd.”
3: (B) goto 5
4: (C) print t0 + ” is even.”
5: (D) end program

• In the given example, we have 4 basic blocks named A, B, C, D.
• A from line 0 to 1, B from line 2 to 3, C for line 4, and D for line 5.
• Here A is the entry block, and D is the Exit block.
• Lines 4 and 5 are JUMP TARGETS.

Cyclomatic Complexity
• It is a measurement concept developed by McCabe.
• It is used to measure the complexity of a program.
• It measures the number of linearly independent paths through a program.
• It is computed using a graph that describes the control flow of the program,
• The nodes of the graph corresponds to the commands of a program.
• A directed edge connects two nodes if the second command is executed immediately
after the first command.
• It is given by
• Where M = cyclomatic complexity
• E = number of edges of the graph
• N = number of nodes of the graph
• P = number of connected components.
• A simple way to determine the cyclomatic number is M = number of closed loops + 1
• It provides an upper bound for number of tests required to guarantee coverage of all program statements.
• It is denoted by V(G) and is given by
V(G) = (# Edges) – (#Nodes) + 1

Control Structure Testing
• In programming, statements are typically executed one after the other and in the
order they are written. However most programming languages have CONTROL
FLOW statements which allow variation in this sequential order.

# Control structures have the following characteristics.
• Statements may only be obeyed under certain conditions (choice statements),
• Statements may be obeyed repeatedly, (looping structures),
• A group of statements may be obeyed (subroutines).

• It consists of the following individual tests.
a) Condition testing,
b) Data Flow testing
c) Loop Testing.

Condition Testing
• The basis for carrying out CONDITION TESTING is the representation of the flow
of control within a program/ subprogram.
• The most important aspect is to ensure that the Boolean controlling expressions
are adequately tested.
• The process of CONDITION TESTING ensures that a controlling expression has
been adequately exercised by constructing a CONSTRAINT SET for every expression
and ensuring that every item in the CONSTRAINT SET is included to test the

• If DateValid then
• While NOT DateValid then

The CONSTRAINT SET for both these expressions is {t,f} which indicates that to
adequately test these expressions they should be tested twice with DateValid
having the values True and False.

• Expanding the Constraint Set, we have the following set of values to be exercised.
{{t,t{ {t,f} {f,t} {f,f}}

• When the simple boolean expression is combined with a relational expression,
then the Constraint set will include more items.

• If only the left hand Boolean value is a relational expression the condition set would be
{{= ,t } {=,f }{> ,t}{< ,t } {>,f } {< ,f }}

• If both Boolean values are relational expressions the condition set would become {{=,=}{=,> }{=,<}{>,=}{<,=} {>,>}{>,< }{<,>} {< ,< }}


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s