简体   繁体   English

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

[英]Viewing Code Coverage Results outside of Visual studio

I've got some unit tests, and got some code coverage data.我进行了一些单元测试,并获得了一些代码覆盖率数据。 Now, I'd like to be able to view that code coverage data outside of visual studio, say in a web browser.现在,我希望能够在 Visual Studio 之外(例如在 Web 浏览器中)查看代码覆盖率数据。 But, when I export the code coverage to an xml file, I can't do anything with it.但是,当我将代码覆盖率导出到 xml 文件时,我无能为力。 Are there readers out there for this?有读者吗? Do I have to write an xml parser and then display it how I want it (seems like a waste since visual studio already does this.) Seems kinda silly to have to take a screenshot of my code coverage results as my "report" Suggestions?我是否必须编写一个 xml 解析器,然后以我想要的方式显示它(这似乎是一种浪费,因为 Visual Studio 已经这样做了。)必须将我的代码覆盖率结果的屏幕截图作为我的“报告”建议似乎有点傻?

This tool https://github.com/danielpalme/ReportGenerator quickly generate Html reports from coverage file.这个工具https://github.com/danielpalme/ReportGenerator从覆盖文件快速生成 Html 报告。 Works quite well and does not require complex activities, can be easily included in the build process.效果很好,不需要复杂的活动,可以很容易地包含在构建过​​程中。

There is this tool called Visual Coverage ( https://github.com/jsargiot/visual-coverage ).有一个名为 Visual Coverage ( https://github.com/jsargiot/visual-coverage ) 的工具。 It takes a .coverage file as input and can export it to clover or html.它需要一个 .coverage 文件作为输入,并且可以将其导出为三叶草或 html。

The page on github shows how to execute and if you're curious you can take a look at the code... github 上的页面显示了如何执行,如果您好奇,可以查看代码...

You can use the tool NDepend and visualize code coverage results imported from NCover , dotCover or Visual Studio coverage .您可以使用工具 NDepend 并可视化NCoverdotCoverVisual Studio 覆盖率导入的代码覆盖率结果 The tool can show code coverage vs. lines of code in a colored treemap.该工具可以在彩色树状图中显示代码覆盖率与代码行的关系 This feature is especially useful to browse at a glance which portion of code is well covered or not by tests.此功能对于一目了然地浏览哪些代码部分被测试很好地覆盖或未覆盖特别有用。

NDepend 彩色树状图代码覆盖率与代码行数

You can also write and apply continuously code rules written over LINQ queries (CQLinq) like:您还可以编写和应用通过 LINQ 查询 (CQLinq) 编写的连续代码规则,例如:

From now, all types added or refactored should be 100% covered by tests 从现在开始,所有添加或重构的类型都应该 100% 被测试覆盖

// <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 }

...or also: ...或者还有:

The panel Search by Coverage can generate such Code Query over LINQ, and displays instantly the matched code elements: Search by Coverage面板可以通过 LINQ 生成这样的代码查询,并立即显示匹配的代码元素:

按覆盖范围搜索方法

Also, the tool can build a HTML/javascript reports that will show code rules violated or code queries results .此外,该工具可以构建HTML/javascript 报告,显示违反的代码规则代码查询结果

Now you can use the tool of dotnet for generate the report in html现在您可以使用 dotnet 工具生成 html 报告

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

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

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

I can't speak for the content of the exported XML, but I'd expect it contain your coverage data as a summary.我不能说导出的 XML 的内容,但我希望它包含您的覆盖数据作为摘要。

The usual thing to do with XML data like this if you want to see it in a web browser page is to convert it to HTML by writing and running a custom XSLT script.如果您想在 Web 浏览器页面中看到这样的 XML 数据,通常的做法是通过编写和运行自定义 XSLT 脚本将其转换为 HTML。 This will presumably get you HTML text and tables containing your data.这可能会为您提供包含数据的 HTML 文本和表格。

If you want to see the coverage data as decorations imposed on the source code, I think you have a much harder problem.如果您想将覆盖数据视为强加在源代码上的装饰,我认为您有一个更难的问题。

我使用 NCover 来完成我所有的代码覆盖,你可以很容易地导出结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM