让 PartCover 发挥作用

发布于 2024-07-09 21:15:26 字数 398 浏览 11 评论 0原文

我想尝试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

江挽川 2024-07-16 21:15:26

是的,我也遇到了这个问题。
查看规则字段的格式。

在浏览器中添加如下内容:

+[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.

爱,才寂寞 2024-07-16 21:15:26

从 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 摘录:

<property name="PartCoverExePath" value="c:\Program Files (x86)\PartCover .NET 2\PartCover.exe" />
<property name="PartCoverWorkPath" value="c:\Projects\MyProject\trunk\CI\" />
<property name="PartCoverSettingsFileName" value="PartCover.Settings.xml" />
<property name="PartCoverReportFileName" value="PartCover.Report.xml" />

<target name="MyTarget">
<exec program="${PartCoverExePath}">
<arg value="--settings "${PartCoverWorkPath}${PartCoverSettingsFileName}"" />
<arg value="--output "${PartCoverWorkPath}${PartCoverReportFileName}"" />
</exec>
</target>

以及 PartCover 设置文件:

<PartCoverSettings>
<Target>C:\CI\Binaries\NUnit2.5.2\bin\net-2.0\nunit-console-x86.exe</Target>
<TargetWorkDir>c:\Projects\MyProject\trunk\MyProject.Test\bin\Debug</TargetWorkDir>
<TargetArgs>MyProject.Test.dll</TargetArgs>
<Rule>+[*]*</Rule>
<Rule>-[log4net*]*</Rule>
<Rule>-[nunit*]*</Rule>
<Rule>-[MyProject.Test*]*</Rule>
</PartCoverSettings>

唷! 希望这能帮其他人解决我所经历的头痛。

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:

<property name="PartCoverExePath" value="c:\Program Files (x86)\PartCover .NET 2\PartCover.exe" />
<property name="PartCoverWorkPath" value="c:\Projects\MyProject\trunk\CI\" />
<property name="PartCoverSettingsFileName" value="PartCover.Settings.xml" />
<property name="PartCoverReportFileName" value="PartCover.Report.xml" />

<target name="MyTarget">
<exec program="${PartCoverExePath}">
<arg value="--settings "${PartCoverWorkPath}${PartCoverSettingsFileName}"" />
<arg value="--output "${PartCoverWorkPath}${PartCoverReportFileName}"" />
</exec>
</target>

And the PartCover settings file:

<PartCoverSettings>
<Target>C:\CI\Binaries\NUnit2.5.2\bin\net-2.0\nunit-console-x86.exe</Target>
<TargetWorkDir>c:\Projects\MyProject\trunk\MyProject.Test\bin\Debug</TargetWorkDir>
<TargetArgs>MyProject.Test.dll</TargetArgs>
<Rule>+[*]*</Rule>
<Rule>-[log4net*]*</Rule>
<Rule>-[nunit*]*</Rule>
<Rule>-[MyProject.Test*]*</Rule>
</PartCoverSettings>

Phew! Hopefully this will save someone else the headaches I had.

时间你老了 2024-07-16 21:15:26

我对 PartCover 报告也有同样的问题。 因此,我一直在努力使其正常工作,但我刚刚发现问题出在 PartCover 发行版附带的两个 XSLT 文件上。

我修复了这些文件,现在一切正常:

按程序集报告

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
  <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">

    <xsl:variable name="cov0style" select="'background:#E79090;text-align:right;'"/>
    <xsl:variable name="cov20style" select="'background:#D79797;text-align:right;'"/>
    <xsl:variable name="cov40style" select="'background:#D7A0A0;text-align:right;'"/>
    <xsl:variable name="cov60style" select="'background:#C7A7A7;text-align:right;'"/>
    <xsl:variable name="cov80style" select="'background:#C0B0B0;text-align:right;'"/>
    <xsl:variable name="cov100style" select="'background:#D7D7D7;text-align:right;'"/>

<table style="border-collapse: collapse;">
  <tr style="font-weight:bold; background:whitesmoke;">
    <td colspan="2">Coverage by assembly</td>
  </tr>

  <xsl:variable name="asms" select="/PartCoverReport/Assembly"/>
  <xsl:for-each select="$asms">
    <xsl:variable name="current-asm-node" select="."/>
    <tr>

      <xsl:element name="td">
        <xsl:attribute name="style">background:ghostwhite; padding: 5px  30px 5px  5px;</xsl:attribute>
        <xsl:value-of select="$current-asm-node/@name"/>
      </xsl:element>

      <xsl:variable name="codeSize" select="sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt/@len)+0"/>
      <xsl:variable name="coveredCodeSize" select="sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt[@visit>0]/@len)+0"/>

      <xsl:element name="td">
        <xsl:if test="$codeSize=0">
          <xsl:attribute name="style">
            <xsl:value-of select="$cov0style"/>
          </xsl:attribute>
          0%
        </xsl:if>
        <xsl:if test="$codeSize > 0">
          <xsl:variable name="coverage" select="ceiling(100 * $coveredCodeSize div $codeSize)"/>
          <xsl:if test="$coverage >=  0 and $coverage < 20">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov20style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 20 and $coverage < 40">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov40style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 40 and $coverage < 60">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov60style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 60 and $coverage < 80">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov80style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 80">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov100style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:value-of select="$coverage"/>%
        </xsl:if>
      </xsl:element>
    </tr>
  </xsl:for-each>
</table>

按班级报告

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="html" indent="no"/>

<xsl:template match="/">

<xsl:variable name="cov0style" select="'background:#FF4040;text-align:right;'"/>
<xsl:variable name="cov20style" select="'background:#F06060;text-align:right;'"/>
<xsl:variable name="cov40style" select="'background:#E78080;text-align:right;'"/>
<xsl:variable name="cov60style" select="'background:#E0A0A0;text-align:right;'"/>
<xsl:variable name="cov80style" select="'background:#D7B0B0;text-align:right;'"/>
<xsl:variable name="cov100style" select="'background:#E0E0E0;text-align:right;'"/>

<table style="border-collapse: collapse;">
    <tr style="font-weight:bold; background:whitesmoke;"><td colspan="2">Coverage by class</td></tr>

    <xsl:for-each select="/PartCoverReport/Type">
        <tr>

            <xsl:element name="td">
                <xsl:attribute name="style">background:ghostwhite; padding: 5px  30px 5px  5px;</xsl:attribute>
                <xsl:value-of select="@name"/>
            </xsl:element>

            <xsl:variable name="codeSize" select="sum(./Method/pt/@len)+0"/>
            <xsl:variable name="coveredCodeSize" select="sum(./Method/pt[@visit>0]/@len)+0"/>

            <xsl:element name="td">
                <xsl:if test="$codeSize=0">
                    <xsl:attribute name="style"><xsl:value-of select="$cov0style"/></xsl:attribute>
                    0%
                </xsl:if>

                <xsl:if test="$codeSize > 0">
                    <xsl:variable name="coverage" select="ceiling(100 * $coveredCodeSize div $codeSize)"/>

                    <xsl:if test="$coverage >=  0 and $coverage < 20"><xsl:attribute name="style"><xsl:value-of select="$cov20style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 20 and $coverage < 40"><xsl:attribute name="style"><xsl:value-of select="$cov40style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 40 and $coverage < 60"><xsl:attribute name="style"><xsl:value-of select="$cov60style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 60 and $coverage < 80"><xsl:attribute name="style"><xsl:value-of select="$cov80style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 80"><xsl:attribute name="style"><xsl:value-of select="$cov100style"/></xsl:attribute></xsl:if>
                    <xsl:value-of select="$coverage"/>%
                </xsl:if>

            </xsl:element>
        </tr>
    </xsl:for-each>
</table>    
</xsl:template>
</xsl:stylesheet>

我希望您觉得这很有用。 此外,欢迎有关此文件的任何反馈,以便我们可以向社区提供正确的文件。 查看此相关问题

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

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
  <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">

    <xsl:variable name="cov0style" select="'background:#E79090;text-align:right;'"/>
    <xsl:variable name="cov20style" select="'background:#D79797;text-align:right;'"/>
    <xsl:variable name="cov40style" select="'background:#D7A0A0;text-align:right;'"/>
    <xsl:variable name="cov60style" select="'background:#C7A7A7;text-align:right;'"/>
    <xsl:variable name="cov80style" select="'background:#C0B0B0;text-align:right;'"/>
    <xsl:variable name="cov100style" select="'background:#D7D7D7;text-align:right;'"/>

<table style="border-collapse: collapse;">
  <tr style="font-weight:bold; background:whitesmoke;">
    <td colspan="2">Coverage by assembly</td>
  </tr>

  <xsl:variable name="asms" select="/PartCoverReport/Assembly"/>
  <xsl:for-each select="$asms">
    <xsl:variable name="current-asm-node" select="."/>
    <tr>

      <xsl:element name="td">
        <xsl:attribute name="style">background:ghostwhite; padding: 5px  30px 5px  5px;</xsl:attribute>
        <xsl:value-of select="$current-asm-node/@name"/>
      </xsl:element>

      <xsl:variable name="codeSize" select="sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt/@len)+0"/>
      <xsl:variable name="coveredCodeSize" select="sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt[@visit>0]/@len)+0"/>

      <xsl:element name="td">
        <xsl:if test="$codeSize=0">
          <xsl:attribute name="style">
            <xsl:value-of select="$cov0style"/>
          </xsl:attribute>
          0%
        </xsl:if>
        <xsl:if test="$codeSize > 0">
          <xsl:variable name="coverage" select="ceiling(100 * $coveredCodeSize div $codeSize)"/>
          <xsl:if test="$coverage >=  0 and $coverage < 20">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov20style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 20 and $coverage < 40">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov40style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 40 and $coverage < 60">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov60style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 60 and $coverage < 80">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov80style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage >= 80">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov100style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:value-of select="$coverage"/>%
        </xsl:if>
      </xsl:element>
    </tr>
  </xsl:for-each>
</table>

report by class

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="html" indent="no"/>

<xsl:template match="/">

<xsl:variable name="cov0style" select="'background:#FF4040;text-align:right;'"/>
<xsl:variable name="cov20style" select="'background:#F06060;text-align:right;'"/>
<xsl:variable name="cov40style" select="'background:#E78080;text-align:right;'"/>
<xsl:variable name="cov60style" select="'background:#E0A0A0;text-align:right;'"/>
<xsl:variable name="cov80style" select="'background:#D7B0B0;text-align:right;'"/>
<xsl:variable name="cov100style" select="'background:#E0E0E0;text-align:right;'"/>

<table style="border-collapse: collapse;">
    <tr style="font-weight:bold; background:whitesmoke;"><td colspan="2">Coverage by class</td></tr>

    <xsl:for-each select="/PartCoverReport/Type">
        <tr>

            <xsl:element name="td">
                <xsl:attribute name="style">background:ghostwhite; padding: 5px  30px 5px  5px;</xsl:attribute>
                <xsl:value-of select="@name"/>
            </xsl:element>

            <xsl:variable name="codeSize" select="sum(./Method/pt/@len)+0"/>
            <xsl:variable name="coveredCodeSize" select="sum(./Method/pt[@visit>0]/@len)+0"/>

            <xsl:element name="td">
                <xsl:if test="$codeSize=0">
                    <xsl:attribute name="style"><xsl:value-of select="$cov0style"/></xsl:attribute>
                    0%
                </xsl:if>

                <xsl:if test="$codeSize > 0">
                    <xsl:variable name="coverage" select="ceiling(100 * $coveredCodeSize div $codeSize)"/>

                    <xsl:if test="$coverage >=  0 and $coverage < 20"><xsl:attribute name="style"><xsl:value-of select="$cov20style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 20 and $coverage < 40"><xsl:attribute name="style"><xsl:value-of select="$cov40style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 40 and $coverage < 60"><xsl:attribute name="style"><xsl:value-of select="$cov60style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 60 and $coverage < 80"><xsl:attribute name="style"><xsl:value-of select="$cov80style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage >= 80"><xsl:attribute name="style"><xsl:value-of select="$cov100style"/></xsl:attribute></xsl:if>
                    <xsl:value-of select="$coverage"/>%
                </xsl:if>

            </xsl:element>
        </tr>
    </xsl:for-each>
</table>    
</xsl:template>
</xsl:stylesheet>

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

沩ん囻菔务 2024-07-16 21:15:26

@pelazm - 感谢您的一些出色指导。

需要添加到您的解决方案中的两件小事情:

(a) 如果您不想使用外部 PartCover.settings.xml

<!-- Runs unit tests through PartCover to calculate unit test covereage-->
<!-- Use %2a instead of * and %3f instead of ? to prevent expansion -->
<!-- %40 = @  %25 = % %24 = $ -->
<Target Name="RunTests">
  <ItemGroup>
     <pc4_settings Include="--target "$(NUnitEXE)""/>
     <pc4_settings Include="--target-work-dir "$(RootDirectory)\src""/>
     <pc4_settings Include="--include [%2a]%2a"/>
     <pc4_settings Include="--exclude [nunit%2a]%2a"/>
     <pc4_settings Include="--exclude [log4net%2a]%2a"/>
     <pc4_settings Include="--exclude [MetadataProcessor.Tests%2a]%2a"/>
   </ItemGroup>

   <CreateItem Include="$(RootDirectory)\src\**\bin\$(Configuration)\*.Tests.dll">
     <Output TaskParameter="Include" ItemName="TestAssemblies" />
   </CreateItem>

   <Exec Command=""$(PartCover4Directory)\PartCover.exe" --register    @(pc4_settings,' ') --target-args "%(TestAssemblies.Identity) $(NUnitArgs) /xml:%(TestAssemblies.Identity).NUnitResults.xml" --output $(BuildDirectory)\PartCover-results.xml"
  ContinueOnError="true"
  WorkingDirectory="$(BuildDirectory)">
     <Output TaskParameter="ExitCode" ItemName="ExitCodes"/>
   </Exec>

   <XslTransformation XslInputPath="$(RootDirectory)\tools\partcover4\xslt\PartCoverFullReport.xslt"
                  XmlInputPaths="$(BuildDirectory)\PartCover-results.xml"
                  OutputPaths="$(BuildDirectory)\PartCover-results-PartCoverFullReport.html" />

   <Error Text="Test error occurred" Condition="'%(ExitCodes.Identity)'>0"/>
 </Target>

(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

<!-- Runs unit tests through PartCover to calculate unit test covereage-->
<!-- Use %2a instead of * and %3f instead of ? to prevent expansion -->
<!-- %40 = @  %25 = % %24 = $ -->
<Target Name="RunTests">
  <ItemGroup>
     <pc4_settings Include="--target "$(NUnitEXE)""/>
     <pc4_settings Include="--target-work-dir "$(RootDirectory)\src""/>
     <pc4_settings Include="--include [%2a]%2a"/>
     <pc4_settings Include="--exclude [nunit%2a]%2a"/>
     <pc4_settings Include="--exclude [log4net%2a]%2a"/>
     <pc4_settings Include="--exclude [MetadataProcessor.Tests%2a]%2a"/>
   </ItemGroup>

   <CreateItem Include="$(RootDirectory)\src\**\bin\$(Configuration)\*.Tests.dll">
     <Output TaskParameter="Include" ItemName="TestAssemblies" />
   </CreateItem>

   <Exec Command=""$(PartCover4Directory)\PartCover.exe" --register    @(pc4_settings,' ') --target-args "%(TestAssemblies.Identity) $(NUnitArgs) /xml:%(TestAssemblies.Identity).NUnitResults.xml" --output $(BuildDirectory)\PartCover-results.xml"
  ContinueOnError="true"
  WorkingDirectory="$(BuildDirectory)">
     <Output TaskParameter="ExitCode" ItemName="ExitCodes"/>
   </Exec>

   <XslTransformation XslInputPath="$(RootDirectory)\tools\partcover4\xslt\PartCoverFullReport.xslt"
                  XmlInputPaths="$(BuildDirectory)\PartCover-results.xml"
                  OutputPaths="$(BuildDirectory)\PartCover-results-PartCoverFullReport.html" />

   <Error Text="Test error occurred" Condition="'%(ExitCodes.Identity)'>0"/>
 </Target>

(b) Gáspár Nagy's HTML report is pretty good - http://gasparnagy.blogspot.com/2010/09/detailed-report-for-partcover-in.html

等待圉鍢 2024-07-16 21:15:26

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文