让 PartCover 发挥作用
我想尝试 PartCover 来实现代码覆盖率。 我正在运行带有 MSTest 的 Visual Studio 2008 Professional。 专业版不包括团队测试工具,例如代码覆盖率。
所以,我正在尝试 PartCover,但无法让它工作。 在 PartCover.Browser 中,我选择了 MSTest 可执行文件,我已将工作参数指向 test.dll,并且尝试将工作目录指向 TestResults 文件夹,但出现错误:
“报告为空检查设置并再次运行目标。”
我不知道下一步该尝试什么。
编辑
事实证明我有两个问题。 首先,我没有制定正确的规则。 其次,我的工作论点中有空格。 空格出现错误,但没有显示在任何地方。
I want to try PartCover for code coverage. I'm running Visual Studio 2008 Professional with MSTest. The Professional Edition does not include the Team Testing tools, like Code Coverage.
So, I'm trying PartCover, but I can't get it to work. In the PartCover.Browser I've selected the MSTest executable, I've pointed the working arguments to my tests.dll, and I've tried pointing my Working Directory to the TestResults folder, but I get an error:
"Report is empty. Check settings and run target again."
I don't know what to try next.
Edit
It turns out I had two problems. First, I wasn't putting my Rules right. Second, I had spaces in my working arguments. The spaces were giving an error, but not showing up anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,我也遇到了这个问题。
查看规则字段的格式。
在浏览器中添加如下内容:
+[MyNamespace.MyAssemblyName]*
其中您指定的程序集名称是包含您想要覆盖的类型的程序集的名称。 从:
+[*]*
开始,partcover 会很乐意为您提供单元测试项目、您引用的任何库等的覆盖率指标。
在命令行中,您可以在 --include 参数中指定相同的模式:
--include=[MyNamespace.MyAssembly]*
您还可以排除包含的命名空间或类型,或者限制您在报告中获取覆盖率数据的命名空间内的类型。 规则的格式是根据手册的正则表达式语法的子集(由作为通配符的星号和组成程序集和类名称的字符组成,因此非常有限,但足以获取您想要的数据)。 查看手册中有关规则的部分。 如果您没有该手册,请从sourceforge 下载。
Yep, I had this problem too.
Check out the format for the Rules field.
In the browser add something like:
+[MyNamespace.MyAssemblyName]*
Where the assembly name you specify is the name of the assembly containing the types you want coverage for. Start off with:
+[*]*
and partcover will happily give you coverage metrics for the unit test project, any libraries you reference and on and on.
From the command line you specify the same pattern in the --include argument:
--include=[MyNamespace.MyAssembly]*
You can also exclude contained namespaces or types or restrict which types from within the namespace you get coverage data for in the report. The format for the rules is a subset of regular expression syntax according to the manual (consisting of asterix as a wildcard and characters that make up assembly and class names, so pretty limited but enough to get the data you want). Check out the section on rules in the manual. If you don't have the manual, download it from sourceforge.
从 NAnt 脚本调用 PartCover 时,我必须执行许多步骤才能最终使 PartCover 正常工作。 我把我必须做的一切都收集在这里,以方便其他人; 请注意,其中一些问题已经被其他人回答了,但我花了很多时间将它们放在一起。
首先,正如此处其他地方的回答,如果您的操作系统是 64 位,则需要运行 [最新的 Windows SDK]\bin\CorFlags.exe [PartCover 安装目录]\PartCover.exe /32BIT+ /Force
这是安装 PartCover 后的一次性步骤。 它将更改可执行文件,并警告您程序集需要重新签名,但我没有这样做,它(最终)工作正常。 请注意,尽管 CorFlags 看起来没有执行您所要求的操作并警告您有关签名的信息,但它确实更改了 .exe,只是没有明确指出这一点。
接下来,如果您的操作系统是 64 位,并且您将 NUnit(或另一个测试 exe)与 PartCover 一起使用,则您将需要调用为 x86 显式编译的版本。 对于 NUnit 来说,这将是 nunit-console-x86.exe。 完成工作后,调用 nunit-console.exe 只会无限期地挂起,并且不会返回提示。
接下来,正如这里其他地方也回答的那样,开发版本 PartCover 2.3 即使在运行 CorFlags 后也会默默地失败。 然而,2.2 有效。
接下来,当调用 PartCover.exe 时,参数的语法为
-- arg-name ... 而 NOT --=arg-name (即破折号破折号空格 arg 名称,而不是破折号破折号等于 arg 名称); PartCover 文档似乎是双向的,但等号对我不起作用。
经过上述操作,PartCover 终于可以在命令行中运行了。 我使用了一个设置文件(您可以使用 PartCover 浏览器 UI 应用程序来保存设置文件,然后您可以从命令行使用该文件),因此我指定的唯一参数是设置文件的完整路径和输出报告文件名称完整路径。
当从 NAnt 脚本调用时,这仍然不起作用,所以我最终意识到必须引用 arg 值......并使用 HTML 编码的标记进行引号。 因此...
Nant 摘录:
以及 PartCover 设置文件:
唷! 希望这能帮其他人解决我所经历的头痛。
I had to go through a number of steps to finally get PartCover working when calling it from a NAnt script. I collected everything I had to do here for others' convenience; note that some of this was already answered by others but I spent tons of time putting it all together.
First, as is answered elsewhere here, if your OS is 64-bit, you'll need to run [most recent Windows SDK]\bin\CorFlags.exe [PartCover install dir]\PartCover.exe /32BIT+ /Force
This is a one-time step, after PartCover install. It will change the executable, and warn you that the assembly will need to be re-signed, but I did not do that and it (eventually) worked fine. Note that even though it looks like CorFlags didn't do what you asked and warned you about signing, it did change the .exe, it just does not point that out explicitly.
Next, again if your OS is 64-bit, and you use NUnit (or another test exe) with PartCover, you will need to invoke a version explicitly compiled for x86. In NUnit's case, that would be nunit-console-x86.exe. Calling nunit-console.exe would just hang indefinitely for me after doing the work, and not return to a prompt.
Next, as is also answered elsewhere here, PartCover 2.3, a dev build, was failing silently even after running CorFlags on it. However, 2.2 worked.
Next, when PartCover.exe is invoked, the syntax for arguments is
-- arg-name ... and NOT --=arg-name (i.e. dash dash space arg name, not dash dash equals arg name); the PartCover docs seem to go both ways but equal sign just did not work for me.
After the above, PartCover was finally working from the command line. I used a settings file (you can use the PartCover browser UI app to save a settings file, which you can then use from the command line), so that the only args I specified were the settings file full path, and the output report file name full path.
This still wasn't working when invoked from a NAnt script, so I finally realized that the arg values had to be quoted... and to use the HTML encoded tokens for quotes. Thus...
NAnt excerpt:
And the PartCover settings file:
Phew! Hopefully this will save someone else the headaches I had.
我对 PartCover 报告也有同样的问题。 因此,我一直在努力使其正常工作,但我刚刚发现问题出在 PartCover 发行版附带的两个 XSLT 文件上。
我修复了这些文件,现在一切正常:
按程序集报告
按班级报告
我希望您觉得这很有用。 此外,欢迎有关此文件的任何反馈,以便我们可以向社区提供正确的文件。 查看此相关问题
I had the same problem with the PartCover reports. So I have been trying to make it work right and I just discovered that the problem was the two XSLT files that come with the PartCover distribution.
I fixed these files and now everything is working fine for me:
report by assembly
report by class
I hope you find this useful. Also, any feedback about this files is welcomed, so we can provide the commutiy with correct files. See this related question
@pelazm - 感谢您的一些出色指导。
需要添加到您的解决方案中的两件小事情:
(a) 如果您不想使用外部 PartCover.settings.xml
(b) Gáspár Nagy 的 HTML 报告非常好 - http://gasparnagy.blogspot.com/2010/09/detailed-report-for-partcover-in.html< /a>
@pelazm - Thanks for some excellent guidance.
Two minor things to add to your solution:
(a) If you don't want to an external PartCover.settings.xml
(b) Gáspár Nagy's HTML report is pretty good - http://gasparnagy.blogspot.com/2010/09/detailed-report-for-partcover-in.html
使用 PartCover 版本 2.3.0.18745 时,我遇到了类似的问题,我的代码未显示在报告中。 使用版本 2.2.0.34631 解决了该问题。
I had similar issues with my code not showing up in the report when using PartCover version 2.3.0.18745. Using version 2.2.0.34631 solved the problem.