Methods directly and indirectly called by test Methods

Code Query Code Coverage

Lists all application methods directly or indirectly called by test methods (methods of the TestCode view tagged with a test attribute). The recursion yields the depthOfCalledByTests metric: 1 = directly called by a test, 2 = called by a method called by a test… Not listed: overrides called through polymorphism, methods solely invoked through a delegate or through reflection.

CQLinq source

This code query 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.

// <Name>Methods directly and indirectly called by test Methods</Name>

let testMethods = TestCode.Methods.Where(m => m.IsTestMethod)

let depthOfCalledByTest = Application.Methods.DepthOfIsUsedByAny(testMethods)
from pair in depthOfCalledByTest
where pair.Value > 0
orderby pair.Value ascending

select new {  
  method = pair.CodeElement, 
  // (depthOfCalledByTests == 1) means that the method is directly called by tests
  // (depthOfCalledByTests == 2) means that the method is directly called by a method directly called by tests
  // …
  depthOfCalledByTests = pair.Value,
  nbLinesOfCode = pair.CodeElement.NbLinesOfCode,
  // --- Uncomment this line if your project import some coverage data ---
  // m.PercentageCoverage
}

//<Desc>
// Lists all application methods *directly or indirectly* called by test
// methods (methods of the **TestCode** view tagged with a test attribute).
// The recursion yields the *depthOfCalledByTests* metric: *1* = directly
// called by a test, *2* = called by a method called by a test… Not listed:
// overrides called through polymorphism, methods solely invoked through a
// delegate or through reflection.
//</Desc>

Code Coverage: all 15 items