As part of Code Quality solution that I have been working on, I developed a utility to upload Visual Studio power tool-generated metrics into database.

To recap, Code Metrics are:

  • Maintainability index (1 to 100 with 100 being the best)
  • Cyclomatic complexity
  • Lines of code
  • Class coupling
  • Depth of inheritance

These are static code analysis metrics that are calculated by VS Power Tool for each assembly. The metrics are groupped by module, namespace, type and member.

Another very useful software quality metrics is Code Coverage which is the ratio of code lines executed during unit test run to the total number of lines. One of the popular tools to generate code coverage is OpenCover. Similar to VS Power Tool, Open Cover reports its result as Xml. Open Cover groups result by module, type and namespace. Unlike first group of metrics, Code Coverage requires unit tests.

For the most parts updating my utility to combine Code Metrics with Code Coverage was straightforward. Some of the challanges were:

  • Metrics hierarchies are different. For example, Code Coverage results don't have namespaces
  • Member (methods) names are very different - System.Void ViewModels.TrafficItem::set_WebServiceTrafficId(System.String) vs WebServiceTrafficId.set(string) : void
  • Merging two metrics trees was another fun challenge

In the end, I was able to achive success merge ratio of 70%-100% when combining these two groups of metrics.