Cyclomatic Complexity (CC)

Cyclomatic Complexity its a type of white box testing for Structural testing use under reference of code complexity.

Facts about why White Box Testing?

  • Most programe coding represents what the program actually dose and not what intended to do.
  • It minimizes delay between defect injection and defect detection.
  • Can catch "obvious" programming errors that do not necessarily map to common user scenarios ( e.g. divide by zero ).

How Cyclomatic Complexity can help ?

Cyclomatic Complexity provides answers to such a questions like :-
  • Which of the paths are independent ?
  • Can we be able to minimize the number of tests of an application?
  • Is there any boundary on the number of tests to be executed to ensure that all statements have been executed at least once ?
Cyclomatic Complexity can provide answers to some of these questions.

Steps in Determining Cyclomatic Complexity :-

  • Start with a conventional flow chart.
  • Identify the "decision points."
  • Convert "complex predicates" to "simple predicates" (see figure below).

  • If there are loops, convert the loop conditions to simple predicates.
  • Combine all the sequential statements into a single node in the flow graph.
  • When a set of sequential statements are followed by a simple predicate, combine all the sequential statements and the predicate check into one node and have two edges emanating out of this node. Nodes with two emanating edges are called predicate nodes.
  • Make sure that all edges terminate in some node, adding a node to represent all the statements at the end of the program.

Example of Cyclomatic Complexity demonstration?

In this post we will demonstrate how to calculate the Cyclomatic Complexity, in order to do the right calculations based on the following flow chart detailing the functions of Java application, which checks to see if a Person's username and password are correct before granting access to an online E-commerce site .

First of all we will create a flow graph/diagram based on the flow chart above .

So lets have a look what have we done here :

 Cyclomatic Complexity = number of edges - number of nodes + 2

= ( 7 - 5 ) +2 = 4

The Cyclomatic Complexity of this software application is 4

I hope i have made a bit of a good explanation of the CC in software testing and quality assurance, any information regarding to this post , please feel free to ask, although i didn't cover everything but the most important things.

About The Author :

Hesham Alssadi
Founder & Author of U.A.E Infographics
Hesham is a Web Developer /Programmer, Technical consultant and analyst who creates scalable technical and creative solutions for both backend implementations and frontend designs.

الآشهر تصفحاً

Related Posts Plugin for WordPress, Blogger...