Test Design StudioGo to Previous Topic: Suppressing RulesGo to Next Topic: File Editors

Code Metrics

Summary

Code Metrics can be generated for your project and will be displayed in the Code Metrics Tool Window.

Generating Code Metrics

To generate code metrics, you simply open the project or solution you would like to analyze. Once open, you may then expand the Tools sub-menu off the Main Menu and either select either the Calculate Code Metrics for Solution command to generate metrics for all projects in the solution or Calculate Code Metrics for Selected Projects command to generated metrics only for the selected projects. The Calculate Code Metrics for Solution command is also available on the toolbar within the Code Metrics Tool Window.

Types of Metrics

Test Design Studio currently generates the metrics listed below. The documentation provided here does not go into an in-depth discussion of each metric as there are numerous publications and discussions widely available. Links to Wikipedia entries have been provided for convenience.
MetricDescription
Maintainability Index

This metric is a value from 0 to 100 that indicates the overall maintainability of the code analyzed. Where direct calculation is not reasonable, this measurement will be the average of the values that are nested under the entry (for instance, a VBScript class will have a maintainability index that is the average of the members defined in that class). This metric is calculated from several other metrics including Cyclomatic Complexity, Lines of Code, and Halstead Volume.

The calculated number is used to determine High, Moderate, or Low maintainability according to the following chart ("High" is a good measurement meaning highly maintainable code with low maintenance cost):
LevelIndex Range
High MaintainabilityBetween 20 and 100 inclusive
Moderate MaintainabilityBetween 10 and 19 inclusive
Low MaintainabilityBetween 0 and 9 inclusive

Cyclomatic Complexity This metric counts the number of paths through code. By default, all code has a single path. Introducing structured code like selection or repetition can increase the number of paths. More information available on Wikipedia.
Lines of Code This metric counts the real lines of code and excludes blank lines and comments.

Use of Metrics

Metrics are meant to provide an objective analysis of a highly subjective topic, and the values must be treated carefully. There are instances where high values for cyclomatic complexity cannot be avoided, and the code can be structured in a way to make it very readable and maintainable.

Use code metrics to identify potentially complicated code. Start by manually inspecting the language elements whose code metrics are the outliers as they are the ones with the highest potential for maintainability issues. A bad metric value does not always equate to poorly implemented code, so be cautious about how you apply metrics within your organization.