3

So I've got this large framework of code written in C# that I would like to start writing unit tests. We have some unit tests but only about 10 to 15 percent code coverage. Obviously, I would like to make my time the most useful and start writing unit tests for the methods with the most references first.

Does anyone know of a code analysis tool that will tell you which methods have the most references? By looking at it this way, I could ensure the most used code is well tested and then work backwards from there or at least get an area to focus most of my efforts on.

4

2 回答 2

3

听起来像是NDepend的工作。

于 2013-07-23T13:33:42.873 回答
2

只是为了稍微改进一下如何使用 NDepend 实现查找引用最多的方法,您只需编写以下代码查询,即可立即获得引用最多的方法。

from m in Application.Methods
orderby m.NbMethodsCallingMe descending
select new { m, m.MethodsCallingMe }

或者,您可以使用度量方法排名(通过在方法的依赖关系图上应用 Google PageRank 算法计算)或方法排名和引用数:

from m in Application.Methods
orderby m.Rank descending
select new { m, m.Rank, m.MethodsCallingMe }

使用 NDepend 查找引用最多的方法


在您的博客文章中,您 (hype8912) 写道:如果您知道 NDepend 的 CQL 语法,您可以通过将当前代码覆盖率结果导入 NDepend 然后修改查询以排除已经具有代码覆盖率的方法,但现在这个对我有用。

代码查询可能如下所示:

from m in Application.Methods
where m.PercentageCoverage < 100
orderby m.Rank descending
select new { m, m.Rank, m.MethodsCallingMe, m.PercentageCoverage, m.NbLinesOfCodeCovered, m.NbLinesOfCodeNotCovered }
于 2013-07-24T14:02:09.537 回答