Monday, November 23, 2015

What is NDepend?

NDepend is a static analysis tool for .NET managed code. This tool supports a large number of code metrics, allows for visualization of dependencies using directed graphs and dependency matrix. The tools also performs code base snapshots comparison, and validation of architectural and quality rules. User-defined rules can be written using LINQ queries. This possibility is named CQLinq. The tool also comes with a large number of predefined CQLinq code rules. Code rules can be checked automatically in Visual Studio or during continuous integration.

Some of NDepend's features include:

Code Rule and Code Query over LINQ (CQLinq)

NDepend lets query the code base over LINQ queries thanks to CQLinq.
For example the following CQLinq query matches all public methods that have more than 30 lines of code: 

from m in Application.Methods  where m.NbLinesOfCode >  30  && m.IsPublic
select m

Around 200 default queries and rules are provided when you create a new NDepend project. They are easy to read and easy to adapt to your need.
Writing CQLinq queries and constraints is straightforward both because it is C# LINQ syntax and because NDepend provides a CQLinq editor which supports:
  • code completion / intellisense
  • live compile error description
  • integrated tooltip documentation

Also, once the query is compiled, it gets executed immediately and its result is well displayed and browsable:





NDepend can be executed as a standalone program as well as a plugin extension within Visual Studio.


Trend Monitoring

NDepend lets create trend charts. Trend charts are made of trend metrics values logged over time at analysis time. More than 50 trend metrics are available per default and it is easy to create your own trend metrics.



Trend charts are displayed on the NDepend dashboard. Some trend charts are available per default to show:
  • Lines of Code
  • Number of Code Rules Violated and number of Code Rules Violations
  • Code Coverage per Tests
  • Max and Average values for various Code Quality Metrics
  • Third-Party Usage
Trend charts can be customized and it is easy to create your own trend charts to show default trend metrics and/or custom trend metrics.

Trend Charts on the NDepend Dashboard
Harness Test Coverage Data

Writing automatic tests is a central practice to increase code correctness. Knowing which part of the code is covered by automatic tests helps improving tests and consequently, it helps increasing code correctness.

NDepend gathers code coverage data from NCover™ and Visual Studio Team System™. From this data, NDepend infers some metrics on methods, types, namespaces and assemblies : PercentageCoverage, NbLinesOfCodeCovered, NbLinesOfCodeNotCovered and BranchCoverage (from NCover only).

These metrics can be used conjointly with others NDepend features. For example you can know what code have been added or refactored since the last release and is not thoroughly covered by tests. You can write a CQLinq rule to continuously check that a set of classes is 100% covered. You can list which complex methods need more tests.

Searching for method more than 90% covered by tests

Another unique usage of code coverage data in NDepend is viusalizing code coverage through the code metric view. See a screenshot below of the metric view on the NDepend code base:
  • Rectangle are methods of the code base.
  • Each rectangle area is proportional to the #lines of code of the method.
  • and the rectangle color is defined by the percentage coverage by tests of the method.
This represents a unique way to understand the code coverage of the application, and see where more effort is needed.

  Selection by Metrics and display the set of methods selected on the Metrics View

Code Quality, 82 Code Metrics


There are many ways to measure a code base. The most common way is to count the number of lines of code. This metric gives a rough estimation of the effort that had been put in to develop the code base. It also allows you to obtain a quality level agreement by pinpointing fat methods and classes.

NDepend counts the number of lines of code. It also comes with 82 other code metrics. Some of them are related to your code organization (the number of classes or namespaces, the number of methods declared in a class...), some of them are related to code quality (complexity, percentage of comments, number of parameters, cohesion of classes, stability of assemblies...), some of them are related to the structure of code (which types are the most used, depth of inheritance...) and some of them are related to code coverage (%coverage, number of lines of code covered, branch coverage...).
  • 12 metrics on application
  • 17 metrics on assemblies
  • 12 metrics on namespaces
  • 22 metrics on types
  • 19 metrics on methods
  • 2 metrics on fields

etc.

NDepend extension provides a Dashboard feature where the overall details of the analyzed code presented in a well defined stucture and graphical format.




 Source: www.ndepend.com

No comments:

Post a Comment