自定义TFS Checkin策略的编程代码覆盖率分析非常缓慢

时间:2011-11-11 12:58:13

标签: c# visual-studio-2010 code-coverage checkin-policy

我正在制定自定义TFS Checkin政策,以确保我们的代码覆盖率高于某个值。我找到了一些例子,现在我试图让他们与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);

}

0 个答案:

没有答案