www.itgalary.com Homepage
Forum Home Forum Home > Testing > Software Testing
  Active Topics Active Topics
  FAQ FAQ  Forum Search   Register Register  Login Login

Code Complexity Testing - Cyclomatic Complexity

 Post Reply Post Reply
Author
Message
  Topic Search Topic Search  Topic Options Topic Options
yogindernath View Drop Down
Newbie
Newbie
Avatar

Joined: 15 Mar 09
Location: New Delhi
Posts: 19
  Quote yogindernath Quote  Post ReplyReply Direct Link To This Post Topic: Code Complexity Testing - Cyclomatic Complexity
    Posted: 25 May 09 at 3:40pm
Two questions coming to mind while doing the code complexity testing are:

Question – 1: Which of the paths are independent?

If two paths are not independent, then we may be able to minimize the number of tests.

Question – 2: Is there any limit on the number of tests that must be run to ensure that all the statements have been executed at least once?

The answer to the above questions is a metric that quantifies the complexity of a program and is known as Cyclomatic Complexity.

It is also known as structural complexity because it gives the internal view of the code. It is a number, which provides us with an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once.

McCabe IO covers about 146 different counts and measures. These metrices are grouped according to six main "collections" each of which provides a different level of granularity and information about the code being analyzed.

The collections of various metrices are as under

1) McCabe Metrics: are based on Cyclomatic Complexity, V(G).

2) Execution Coverage metrics: are based on any of Branch, Path or Boolean coverage.

3) Code Grammar metrics: are based around line counts and code structure counts such as Nesting.

4) 00 metrics: are based on the work of Chidamber and Kemerer.

5) Derived Metrics: are based on abstract concepts such as understability, maintainability, comprehension and testability.

6) Custom Metrics: are imported from third party software / systems, e.g. defects count.
McCabe IO provides for about 100 individual metrics at the Method, Procedure, Function, Control and Section / paragraph level. 40 additional metrices are available at the class / file and program level.

Categories of Metrics: There are three categories of metrics

1) McCabe Metrics.

2) 00 Metrics.

3) Grammar Metrics.

When collecting metrics, we rely upon subordinates who need to 'buy into' the metrics program. Hence, it is important to only collect what you intend to use. We should remember, 'The Hawthorne Effect' which states that when you collect metrics on people, the people being measured will change their behavior. Either of these practices will destroy the efficiency of any metrics program.

Let us discuss the above mentioned three metrics categories

1) McCabe Metrics:

a) Cyclomatic Complexity, V(G) : It is the measure of the amount of logic in a code module of 3rd and 4th generation languages. If V(G) is excessively high then it leads to impenetrable code i.e., a code which is at higher risk due to difficulty in testing. The threshold value is 10. When V(G) > 10; then the likelihood of code being unreliable is much higher. It must be remembered that a high V(G) shows a decreased quality in the code resulting in higher defect that become costly to fix.



Back to Top
tester View Drop Down
Groupie
Groupie


Joined: 28 Jun 10
Posts: 46
  Quote tester Quote  Post ReplyReply Direct Link To This Post Posted: 28 Jun 10 at 10:20am
Hi,

There is also another method for calculating cyclomatic complexity
cyclomatic complexity= E-N+1
E= No of edges in graph
N= No of nodes in graph


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

.