Sounds like a job for NDepend.
Find methods with most references
-
03-06-2022 - |
Domanda
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.
Soluzione
Altri suggerimenti
Just to refine a bit on how to achieve finding methods with most references with NDepend, you just have to write the following Code Query, and you instantly get the most referenced methods.
from m in Application.Methods
orderby m.NbMethodsCallingMe descending
select new { m, m.MethodsCallingMe }
Alternatively you can use the metric Method Rank (computed by applying the Google PageRank algorithm on the graph of methods' dependencies) or both method rank and # of references:
from m in Application.Methods
orderby m.Rank descending
select new { m, m.Rank, m.MethodsCallingMe }
On your blog post you (hype8912) wrote: If you know the CQL syntax for NDepend, you could take this farther by importing your current code coverage results into NDepend and then modifying the query to exclude methods that already have code coverage but for now this works good for me.
The code query could then look like:
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 }