【问题标题】:vstest.console.exe generate cover for only Moq.dllvstest.console.exe 仅为 Moq.dll 生成封面
【发布时间】:2018-02-06 12:55:27
【问题描述】:

我正在尝试使用 vstest.console.exe 生成代码覆盖率报告。我也在使用 .runsettings 文件并将其作为参数传递。

无论我想做什么,它都会为 moq.dll 生成一个覆盖率报告。

我在下面分享我正在运行的命令参数的全文以及 .runsettings 文件的内容。任何想法,我在哪里做错了什么?

命令:

vstest.console.exe “C:\Xyz.Tests\bin\Debug\netcoreapp2.0\Xyz.Tests.dll”/InIsolation /EnableCodeCoverage /settings:CodeCoverage.runsettings

CodeCoverage.runsettings 文件内容:

<RunSettings>
<DataCollectionRunSettings>
  <DataCollectors>
    <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" enabled="false">
      <Configuration>
        <CodeCoverage>
        </CodeCoverage>
      </Configuration>
    </DataCollector>
  </DataCollectors>
</DataCollectionRunSettings>
</RunSettings>

生成的代码覆盖率报告图片:

【问题讨论】:

    标签: c# .net-core code-coverage vstest.console.exe runsettings


    【解决方案1】:

    我遇到了同样的行为,但幸运的是我找到了解决方案:

    打开 Visual Studio 测试任务并:

  • 取消选中Code coverage enabled标志
  • --collect:"Code Coverage" 放入其他控制台选项中
  • 编辑项目的.csproj文件,包含测试的类和:

    &lt;PropertyGroup&gt;部分添加&lt;DebugType&gt;full&lt;/DebugType&gt;

    为了避免代码覆盖结果中出现 moq.dll:

    在 .runsettings 文件的 &lt;ModulePaths&gt; -&gt; &lt;Exclude&gt; 部分添加 &lt;ModulePath&gt;.*moq.dll&lt;/ModulePath&gt;

    这是我的 .runsettings

    <?xml version="1.0" encoding="utf-8"?>
    <RunSettings>
      <RunConfiguration>
        <MaxCpuCount>0</MaxCpuCount>
      </RunConfiguration>
      <DataCollectionRunSettings>
        <DataCollectors>
          <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
            <Configuration>
              <CodeCoverage>
                <!-- Match assembly file paths: -->
                <ModulePaths>
                  <Include>
                    <ModulePath>.*\.dll$</ModulePath>
                    <ModulePath>.*\.exe$</ModulePath>
                  </Include>
                  <Exclude>
                    <ModulePath>.*moq.dll</ModulePath>
                    <ModulePath>.*CPPUnitTestFramework.*</ModulePath>
                    <ModulePath>.*TestAdapter.*</ModulePath>
                  </Exclude>
                </ModulePaths>
              </CodeCoverage>
            </Configuration>
          </DataCollector>
        </DataCollectors>
      </DataCollectionRunSettings>
    </RunSettings>
    

    请查看https://developercommunity.visualstudio.com/content/problem/92905/net-core-unit-testing-code-coverage.html链接

    【讨论】:

    • 感谢 Alxander,这个解决方案对我有用。似乎最重要的部分是将 full 添加到项目中。
    猜你喜欢
    • 1970-01-01
    • 2015-09-01
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多