我正在制定自定义 TFS 签入策略,以确保我们的代码覆盖率高于某个值。我找到了一些示例,现在我正试图让它们与 VS 2010 一起使用。
目前我有一些正在运行的代码,它似乎正在运行,只是它真的很慢。很难说哪条线路“最慢”。也许是更多的数据量。
有人知道我可以如何优化这段代码吗?
private static decimal CalculateTotalCodeCoverage(string binariesFolder, string codeCoverageFile)
{
int blocksCovered = 0;
int blocksNotCovered = 0;
using (CoverageInfo info = CoverageInfo.CreateFromFile(codeCoverageFile,
new string[] { binariesFolder },
new string[] { binariesFolder }))
{
List<BlockLineRange> lines = new List<BlockLineRange>();
foreach (ICoverageModule module in info.Modules)
{
byte[] coverageBuffer = module.GetCoverageBuffer(null);
using (ISymbolReader reader = module.Symbols.CreateReader())
{
uint methodId;
string methodName;
string undecoratedMethodName;
string className;
string namespaceName;
lines.Clear();
while (reader.GetNextMethod(
out methodId,
out methodName,
out undecoratedMethodName,
out className,
out namespaceName,
lines))
{
CoverageStatistics stats = CoverageInfo.GetMethodStatistics(coverageBuffer, lines);
blocksCovered += stats.BlocksCovered;
blocksNotCovered += stats.BlocksNotCovered;
}
}
}
}
return GetPercentCoverage(blocksCovered, blocksNotCovered);
}