在Visual Studio之外查看代码覆盖率结果

时间:2009-07-22 18:18:37

标签: c# code-coverage code-analysis report

我有一些单元测试,并获得了一些代码覆盖率数据。现在,我希望能够在Visual Studio之外查看代码覆盖率数据,比如在Web浏览器中。但是,当我将代码覆盖率导出到xml文件时,我无法对其进行任何操作。那里有读者吗?我是否必须编写一个xml解析器,然后按照我想要的方式显示它(看起来像是浪费,因为visual studio已经这样​​做了。)看起来有点傻到必须把我的代码覆盖率结果截图作为我的“报告” 建议?

7 个答案:

答案 0 :(得分:10)

此工具https://github.com/danielpalme/ReportGenerator可快速从coverage文件生成Html报告。工作得很好,不需要复杂的活动,可以很容易地包含在构建过​​程中。

答案 1 :(得分:3)

有一个名为Visual Coverage(https://github.com/jsargiot/visual-coverage)的工具。它需要一个.coverage文件作为输入,并可以将其导出到三叶草或html。

github上的页面显示了如何执行,如果你很好奇,你可以查看代码......

答案 2 :(得分:1)

您可以使用从 NCover dotCover Visual Studio coverage 导入的工具NDepend和visualize code coverage results。该工具可以在彩色树形图中显示code coverage vs. lines of code。此功能对于一目了然地浏览哪些代码部分被测试覆盖得非常有用。

NDepend colored treemap code coverage vs. lines of code

您也可以连续撰写和申请code rules written over LINQ queries (CQLinq),如:

From now, all types added or refactored should be 100% covered by tests

// <Name>From now, all types added or refactored should be 100% covered by tests</Name>
warnif count > 0 from t in JustMyCode.Types where

  // Match methods new or modified since Baseline for Comparison...
  (t.WasAdded() || t.CodeWasChanged()) &&

  // ...that are not 100% covered by tests
  t.PercentageCoverage < 100

  let methodsCulprit = t.Methods.Where(m => m.PercentageCoverage < 100)

select new { t, t.PercentageCoverage, methodsCulprit }

......还是:

面板按覆盖率搜索可以通过LINQ生成此类代码查询,并立即显示匹配的代码元素:

Search methods by coverage

此外,该工具可以构建一个HTML/javascript reports来显示违反的代码规则代码查询结果

答案 3 :(得分:0)

我不能代表导出的XML的内容,但我希望它包含您的覆盖数据作为摘要。

如果您希望在Web浏览器页面中看到这样的XML数据,通常可以通过编写和运行自定义XSLT脚本将其转换为HTML。这可能会为您提供包含数据的HTML文本和表格。

如果您希望将覆盖数据视为对源代码强加的装饰,我认为您有一个更难的问题。

答案 4 :(得分:0)

现在可以使用dotnet工具生成html报告了

dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator
"-reports:Path\To\TestProject\TestResults\{guid}\coverage.cobertura.xml"
"-targetdir:coveragereport"
-reporttypes:Html

来源:https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage?tabs=linux#generate-reports

答案 5 :(得分:-1)

我使用NCover来完成所有代码覆盖,并且您可以非常轻松地导出结果

答案 6 :(得分:-1)

可能有帮助:您可以在“代码覆盖率结果”窗格中打开所有覆盖率数据,然后将其复制并粘贴到Excel ...