9th March 2017 Olivier

Calculating technical debt with NDepend

For once we leave development with a bit of devops (in the broad sense).

NDepend (www.ndepend.com) is a great tool that allows quality control on the code. It does not scan the source code itself, but make an analysis of the executables or libraries generated.

He gives us an amount of info, like complexity, graph of dependencies, rules and best practices that are broken, etc…

One of the novelties of version 2017 is the smart calculation of technical debt.

Only – what technical debt? Basically, it is the difficulties that will happen in the future during maintenance or evolution of the application, because of a bad design or poor quality of the code (https://en.wikipedia.org/wiki/Technical_debt)

Ndepend is using Rules. These are rules (surprise!) that are used to check the quality of the code. You can assign a formula (or a number) that allows to calculate the debt. NDpend checks the Rules and calculates the debt according to those who are broken.

Also, NDepend takes a baseline, that is a version of the application used as a basis. When we re-launch NDepend on the new version of the code, it will then show the evolution compared to this baseline (baseline that can be changed at any time).

It allows, for example, after you refactored or add a feature, what is the impact compared to the basic version. Very convenient to use before pushing on the source control!

So let’s try

First launch

I create 2 projects (a console, and a unit test). There is a Quality Gate (a kind of meta rule, like “you must have at least 80% of code coverage”) on the code coverage that generates debt if some threshold not reached. I’ll use it in my example. I only add the console project to NDpend analysis.

This is the superb code of a class:

Here is the test code

Great, as you can see, the code coverage won’t be famous! And indeed:


16.67%. Debt of 52 minutes. And 2 quality gates are broken


The broken gates quality are the low percentage of code coverage, and a low debt rating. As seen on the chart here after, it is a bit too red. Let’s fix it!


Second launch

We improve the tests:

It should be better. Indeed:


Debt goes from D to C. Debt reduction of 13 minutes, the code coverage passes 75% and no more quality gates broken.

Also, a lot more green:



I only scratched the possibilities of NDepend. If launch you the HTML report, you will see that there are a lot of things to explore.


A tool very useful to see the code from all angles. It allows to see things that are not necessarily thought about when you stay deep into Visual Studio for a long time. A nice habit to launch it before a commit, just to see if it not too forced on beer at lunchtime!

I hope I make you want to try!

Mobile and Mixed Reality engineer , Arcana Studio
follow me

Leave a Reply

Your email address will not be published. Required fields are marked *