C# 在 Visual Studio 之外查看代码覆盖率结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1167182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Viewing Code Coverage Results outside of Visual studio
提问by
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. But, when I export the code coverage to an xml file, I can't do anything with it. 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?
我进行了一些单元测试,并获得了一些代码覆盖率数据。现在,我希望能够在 Visual Studio 之外(例如在 Web 浏览器中)查看代码覆盖率数据。但是,当我将代码覆盖率导出到 xml 文件时,我无能为力。有读者吗?我是否必须编写一个 xml 解析器,然后以我想要的方式显示它(这似乎是一种浪费,因为 Visual Studio 已经这样做了。)必须将我的代码覆盖率结果的屏幕截图作为我的“报告”建议似乎有点傻?
回答by AutomatedTester
I use NCover to do all my code coverage and you have the ability to export the results quite easily
我使用 NCover 来完成我所有的代码覆盖,你可以很容易地导出结果
回答by Ira Baxter
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. This will presumably get you HTML text and tables containing your data.
如果您想在 Web 浏览器页面中看到这样的 XML 数据,通常的做法是通过编写和运行自定义 XSLT 脚本将其转换为 HTML。这可能会为您提供包含数据的 HTML 文本和表格。
If you want to see the coverage data as decorations imposed on the source code, I think you have a much harder problem.
如果您想将覆盖数据视为强加在源代码上的装饰,我认为您有一个更难的问题。
回答by Patrick from NDepend team
You can use the tool NDepend and visualize code coverage resultsimported from NCover, dotCoveror Visual Studio coverage. The tool can show code coverage vs. lines of codein 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 并可视化从NCover、dotCover或Visual Studio 覆盖率导入的代码覆盖率结果。该工具可以在彩色树状图中显示代码覆盖率与代码行数。此功能对于一目了然地浏览哪些代码部分被测试很好地覆盖或未覆盖特别有用。
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:
...或者还有:
- Types that used to be 100% covered but not anymore
- C.R.A.P method code metric
- Complex methods partially covered by tests should be 100% covered
The panel Search by Coveragecan 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 reportsthat will show code rules violatedor code queries results.
此外,该工具可以构建HTML/javascript 报告,显示违反的代码规则或代码查询结果。
回答by Jo?o Pedro 'jota' Martins
Might help: you can open all the coverage data in the Code Coverage Results pane and copy&paste it to Excel...
可能有帮助:您可以在代码覆盖率结果窗格中打开所有覆盖率数据并将其复制并粘贴到 Excel...
回答by Luke Syvil
There is this tool called Visual Coverage (https://github.com/jsargiot/visual-coverage). It takes a .coverage file as input and can export it to clover or html.
有一个名为 Visual Coverage ( https://github.com/jsargiot/visual-coverage) 的工具。它需要一个 .coverage 文件作为输入,并且可以将其导出为三叶草或 html。
The page on github shows how to execute and if you're curious you can take a look at the code...
github 上的页面显示了如何执行,如果您好奇,可以查看代码...
回答by massimogentilini
This tool https://github.com/danielpalme/ReportGeneratorquickly generate Html reports from coverage file. Works quite well and does not require complex activities, can be easily included in the build process.
这个工具https://github.com/danielpalme/ReportGenerator从覆盖文件快速生成 Html 报告。效果很好,不需要复杂的活动,可以很容易地包含在构建过程中。