Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009.

Slides:



Advertisements
Similar presentations
Chapter 14 Software Testing Techniques - Testing fundamentals - White-box testing - Black-box testing - Object-oriented testing methods (Source: Pressman,
Advertisements

Whitebox Testing Fra: CS Fall Whitebox Testing AKA Structural, Basis Path Test Normally used at unit level Assumes errors at unit level are.
1 Ivan Marsic Rutgers University LECTURE 15: Software Complexity Metrics.
CYCLOMATIC COMPLEXITY 1. Invented by Thomas McCabe (1974) to measure the complexity of a program ’ s conditional logic Cyclomatic complexity of graph.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Metrics Project and Process Metrics. Why do we measure? Assessing project status Allows us to track risks Before they go critical Adjust workflow See.
Creator: ACSession No: 13 Slide No: 1Reviewer: SS CSE300Advanced Software EngineeringFebruary 2006 Testing - Techniques CSE300 Advanced Software Engineering.
Chapter 17 Software Testing Techniques
Software engineering for real-time systems
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
BASIS PATH TESTING ● By Tom McCabe ● McCabe, T., "A Software Complexity Measure," IEEE Trans. Software Engineering, vol. SE-2, December 1976, pp
Chapter 18 Testing Conventional Applications
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Unit Testing CS 414 – Software Engineering I Don Bagert Rose-Hulman Institute of Technology January 16, 2003.
Software Engineering Lecture 12 Software Testing Techniques 1.
Chapter 13 & 14 Software Testing Strategies and Techniques
1 The Relationship of Cyclomatic Complexity, Essential Complexity and Error Rates Mike Chapman and Dan Solomon
A Complexity Measure THOMAS J. McCABE Presented by Sarochapol Rattanasopinswat.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
CMSC 345 Fall 2000 Unit Testing. The testing process.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
Software Testing The process of operating a system or component under specified conditions, observing and recording the results, and making an evaluation.
Agenda Introduction Overview of White-box testing Basis path testing
INTRUDUCTION TO SOFTWARE TESTING TECHNIQUES BY PRADEEP I.
These slides are designed to accompany Software Engineering: A Practitioner’s Approach, 6/e (McGraw-Hill 2005). Slides copyright 2005 by Roger Pressman.1.
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
BASIS PATH TESTING.
Creator: ACSession No: 7 Slide No: 1Reviewer: SS CSE300Advanced Software EngineeringSeptember 2005 Software Measurement – Estimation and Productivity CSE300.
White Box Testing Arun Lakhotia University of Southwestern Louisiana P.O. Box Lafayette, LA 70504, USA
Theory and Practice of Software Testing
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Agent program is the one part(class)of Othello program. How many test cases do you have to test? Reversi [Othello]
White Box Testing by : Andika Bayu H.
Cyclomatic complexity (or conditional complexity) is a software metric (measurement). Its gives the number of indepented paths through strongly connected.
These slides are designed to accompany Software Engineering: A Practitioner’s Approach, 7/e (McGraw-Hill 2009). Slides copyright 2009 by Roger Pressman.1.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Cyclomatic Complexity Philippe CHARMAN Last update:
Software Testing Techniques Presented By Dr. Shazzad Hosain.
CS223: Software Engineering Lecture 21: Unit Testing Metric.
1 Lecture 14: Chapter 18 Testing Conventional Applications Slide Set to accompany Software Engineering: A Practitioner’s Approach, 7/e by Roger S. Pressman.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
White Box Testing. Agenda White-box vs Black-box Program Flow Controls White-box Test Methods Exercises Complexity Q&A.
Chapter 17 Software Testing Techniques
BASIS PATH TESTING.
Cyclomatic Complexity
Software Metrics 1.
Software Testing.
White-Box Testing Pfleeger, S. Software Engineering Theory and Practice 2nd Edition. Prentice Hall, Ghezzi, C. et al., Fundamentals of Software Engineering.
Software Testing.
Software Engineering (CSI 321)
Chapter 13 & 14 Software Testing Strategies and Techniques
Data Coverage and Code Coverage
Structural testing, Path Testing
White Box Testing.
Cyclomatic Complexity
Cyclomatic Complexity
Software Testing (Lecture 11-a)
Cyclomatic Complexity
Halstead software science measures and other metrics for source code
Cyclomatic Complexity
How does the complexity of the flow of control affect test cases?
Chapter 18 Testing Conventional Applications
Chapter 10 – Software Testing
Cyclomatic Complexity
Software Testing “If you can’t test it, you can’t design it”
1. Cyclomatic complexity
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Unit III – Chapter 3 Path Testing.
Presentation transcript:

Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009

What is it?  A software metric used to measure the complexity of software  Developed by Thomas McCabe  Described (informally) as the number of simple decision points + 1  A software metric used to measure the complexity of software  Developed by Thomas McCabe  Described (informally) as the number of simple decision points + 1

What is it?  Essentially the number of linearly independent paths through the code  The code has no decision statements: complexity = 1  The code has an if statement, there are two paths through the code: complexity = 2  Essentially the number of linearly independent paths through the code  The code has no decision statements: complexity = 1  The code has an if statement, there are two paths through the code: complexity = 2

Cyclomatic Complexity V(G) Computing the cyclomatic complexity: number of simple decisions + 1 In this case, V(G) = 4 From Pressman Slides - Software Engineering a Practical Approach 6,e

Cyclomatic Complexity V(G) This is NOT a simple decision! These are simple decisions! Convert To A simple decision chooses one of two options

Steps to calculate complexity  Draw the control flow graph of the code  Count the number of edges = E  Count the number of nodes = N  Count the number of connected components = P  Complexity = M – N + 2P  What is the complexity for the graph?  Draw the control flow graph of the code  Count the number of edges = E  Count the number of nodes = N  Count the number of connected components = P  Complexity = M – N + 2P  What is the complexity for the graph?

Graph Complexity (Cyclomatic Complexity) A number of industry studies have indicated that the higher V(G), the higher the probability or errors. V(G) modules modules in this range are more error prone From Pressman Slides - Software Engineering a Practical Approach 6,e

Basis Path Testing Next, we derive the independent paths: Since V(G) = 4, there are four paths Path 1: 1,2,3,6,7,8 Path 2: 1,2,3,5,7,8 Path 3: 1,2,4,7,8 Path 4: 1,2,4,7,2,4,...7,8 Finally, we derive test cases to exercise these paths From Pressman Slides - Software Engineering a Practical Approach 6,e

What is the complexity? public void howComplex(i) { while (i<10) { i++; System.out.printf("i is %d", i); if (i%2 == 0) { System.out.println("even"); } else { System.out.println("odd"); }

What is the complexity V(G)? public void howComplex() { int i=20; while (i<10) { System.out.printf("i is %d", i); if (i%2 == 0) { System.out.println("even"); } else { System.out.println("odd"); } V(G) = 2 decisions + 1 = 3

Output from JavaNCSS NCSS = Non Commenting Source Statements CCN = cyclomatic complexity number

Better Tool Found (Nov 2009)  RefactorIt    Provides Cyclomatic Complexity many other metrics, and refactoring tools  Comment density  Coupling  Depth of inheritance,  …  RefactorIt    Provides Cyclomatic Complexity many other metrics, and refactoring tools  Comment density  Coupling  Depth of inheritance,  …