Percentage Coverage on Refactored Code

Quality Gate Quality Gates

Refactored Code = methods where code was changed since the baseline (comment/formatting changes excluded). When refactoring, also write tests to reach 100% coverage.

The ~10% of a class that is hard to cover is not easily testable, hence badly designed and often error-prone: 100% coverage ensures this code gets tested.

CQLinq source

This quality gate is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <QualityGate Name="Percentage Coverage on Refactored Code" Unit="%" />
failif value < 70%
warnif value < 80%
let newMethods = Application.Methods.Where(m => m.CodeWasChanged() && m.NbLinesOfCode > 0)
let locCovered = newMethods.Sum(m => m.NbLinesOfCodeCovered)
let loc = newMethods.Sum(m => m.NbLinesOfCode)
select 100d * locCovered / loc

//<Desc>
// *Refactored Code* = methods where *code was changed* since the baseline
// (comment/formatting changes excluded). When refactoring, also write tests
// to reach 100% coverage.
//
// The ~10% of a class that is hard to cover is not easily testable, hence
// badly designed and often **error-prone**: 100% coverage ensures this code
// gets tested.
//</Desc>

Quality Gates: all 19 items