Presentation is loading. Please wait.

Presentation is loading. Please wait.

Predicting Class Testability using Object-Oriented Metrics M. Bruntink and A. van Deursen Presented by Tom Chappell.

Similar presentations


Presentation on theme: "Predicting Class Testability using Object-Oriented Metrics M. Bruntink and A. van Deursen Presented by Tom Chappell."— Presentation transcript:

1 Predicting Class Testability using Object-Oriented Metrics M. Bruntink and A. van Deursen Presented by Tom Chappell

2 Goal To assess the capability of certain object- oriented metrics to predict class testability To assess the capability of certain object- oriented metrics to predict class testability Useful for: Useful for: Planning Planning Design Design Monitoring Monitoring

3 Source Code Metrics LOCC – Lines of Code Per Class LOCC – Lines of Code Per Class The number of lines of source code, not including blank lines and comments The number of lines of source code, not including blank lines and comments FOUT – Fan Out FOUT – Fan Out The number of classes used by a class The number of classes used by a class

4 Source Code Metrics NOM – Number of Methods NOM – Number of Methods Counts the number of new methods declared by a class Counts the number of new methods declared by a class Does not count methods inherited from superclass, even if overridden Does not count methods inherited from superclass, even if overridden

5 Source Code Metrics NOF – Number of Fields NOF – Number of Fields Counts the number of new fields (class variables and member variables) declared by a class Counts the number of new fields (class variables and member variables) declared by a class Does not count fields inherited from superclass Does not count fields inherited from superclass

6 Source Code Metrics RFC – Response for Class RFC – Response for Class The number of methods in a class (including inherited methods) plus the number of methods of other classes invoked by that class The number of methods in a class (including inherited methods) plus the number of methods of other classes invoked by that class

7 Source Code Metrics DIT – Depth of Inheritance Tree DIT – Depth of Inheritance Tree The number of ancestors of a class The number of ancestors of a class NOC – Number of Children Classes NOC – Number of Children Classes Counts only the immediate subclasses, not all descendents Counts only the immediate subclasses, not all descendents

8 Source Code Metrics WMC – Weighted Methods per Class WMC – Weighted Methods per Class The total of McCabe’s Cyclomatic Complexity for each method implemented by the class The total of McCabe’s Cyclomatic Complexity for each method implemented by the class Cyclomatic Complexity is the number of distinct execution paths in the method Cyclomatic Complexity is the number of distinct execution paths in the method

9 Source Code Metrics LCOM – Lack of Cohesion of Methods LCOM – Lack of Cohesion of Methods 0: every field of the class is used by every method of the class (Lower Bound) 0: every field of the class is used by every method of the class (Lower Bound) 1: every field of the class is used by one method of the class 1: every field of the class is used by one method of the class n / (n-1): no field of the class is used by any of the n methods of the class (Upper Bound) n / (n-1): no field of the class is used by any of the n methods of the class (Upper Bound) Defined for classes with at least 1 field and at least 2 methods Defined for classes with at least 1 field and at least 2 methods

10 Test Suite Metrics dLOCC – Lines of Code for [Test] Class dLOCC – Lines of Code for [Test] Class The number of lines of source code in a test class, not including blank lines and comments The number of lines of source code in a test class, not including blank lines and comments dNOTC – Number of Test Cases dNOTC – Number of Test Cases The number of times that a test class calls a JUnit assert method. The number of times that a test class calls a JUnit assert method.

11 Case Studies DocGen DocGen Commercial documentation generator Commercial documentation generator 90,000 lines of Java code 90,000 lines of Java code 640 classes (138 with associated test classes) 640 classes (138 with associated test classes) Developed with XP methodology Developed with XP methodology Coding standard: method not allowed to exceed 12 lines Coding standard: method not allowed to exceed 12 lines

12 Case Studies Apache Ant Apache Ant Open Source build tool (similar to “make”) Open Source build tool (similar to “make”) 170,000 lines of Java code 170,000 lines of Java code 887 classes (111 with associated test classes) 887 classes (111 with associated test classes)

13 Results Strong Predictors of High dLOCC (Lines of [Test] Class Code): Strong Predictors of High dLOCC (Lines of [Test] Class Code): RFC – Response for Class RFC – Response for Class LOCC – Lines of [Source] Class Code LOCC – Lines of [Source] Class Code FOUT – Fan Out FOUT – Fan Out WMC – Weighted Method Count WMC – Weighted Method Count NOM – Number of Methods NOM – Number of Methods NOF – Number of Fields NOF – Number of Fields

14 Results Strong Predictors of High dNOTC (Number of Test Cases): Strong Predictors of High dNOTC (Number of Test Cases): RFC – Response for Class (DocGen Only) RFC – Response for Class (DocGen Only) LOCC – Lines of [Source] Class Code (DocGen Only) LOCC – Lines of [Source] Class Code (DocGen Only)

15 Results LCOM – Lack of Cohesion of Methods LCOM – Lack of Cohesion of Methods Moderately correlated to dLOCC/dNOTC in Ant Moderately correlated to dLOCC/dNOTC in Ant Much less strongly correlated in DocGen Much less strongly correlated in DocGen DocGen’s “12 lines per method” coding standard increases LCOM DocGen’s “12 lines per method” coding standard increases LCOM

16 Comments Choice of Correlation Statistic Choice of Correlation Statistic The authors use Spearman’s rank-order correlation coefficient ( r s ) The authors use Spearman’s rank-order correlation coefficient ( r s ) This measures only rank-order correlation (“the class with the 13 th -highest number of LOCC had the 13 th -highest dLOCC”) This measures only rank-order correlation (“the class with the 13 th -highest number of LOCC had the 13 th -highest dLOCC”) The degree that a change in LOCC would cause to change in dLOCC is not measured The degree that a change in LOCC would cause to change in dLOCC is not measured

17 Comments Suggested Metric: %Interface Fan Out Suggested Metric: %Interface Fan Out Measures the percentage of fan-out references that refer to interfaces, rather than to classes Measures the percentage of fan-out references that refer to interfaces, rather than to classes Designing APIs to use interfaces makes classes more flexible and makes it easier for the unit test to set up a test environment using test stub classes that implement required interfaces Designing APIs to use interfaces makes classes more flexible and makes it easier for the unit test to set up a test environment using test stub classes that implement required interfaces

18 Questions?


Download ppt "Predicting Class Testability using Object-Oriented Metrics M. Bruntink and A. van Deursen Presented by Tom Chappell."

Similar presentations


Ads by Google