Percentage Coverage

Quality Gate Quality Gates

Code coverage measures how much code is executed by tests; high coverage suggests fewer undetected bugs. Coverage alone is not enough: tests must fail explicitly when a check/assertion gets unvalidated.

Warns below 80%, fails below 70% (indicative, the more the better). Aim for 100% coverage on new and refactored classes, with many checks/assertions.

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" Unit="%" />
failif value < 70%
warnif value < 80%
// Coverage of the application code only: test code (the TestCode view) is not counted
let covered    = (double)Application.Assemblies.Sum(a => a.NbLinesOfCodeCovered ?? 0)
let notCovered = (double)Application.Assemblies.Sum(a => a.NbLinesOfCodeNotCovered ?? 0)
select (covered + notCovered) == 0d ? (double?)null : 100d * covered / (covered + notCovered)

//<Desc>
// Code coverage measures how much code is executed by tests; high coverage
// suggests fewer undetected bugs. Coverage alone is not enough: tests must
// fail explicitly when a check/assertion gets unvalidated.
//
// Warns below 80%, fails below 70% (indicative, the more the better). Aim for
// 100% coverage on new and refactored classes, with many checks/assertions.
//</Desc>

Quality Gates: all 19 items