使用.runsettings文件时,代码覆盖率中不包含异步方法

时间:2015-12-11 04:28:29

标签: c# unit-testing asynchronous code-coverage

每当我通过我的解决方案运行Visual Studio 2015代码覆盖率而不指定测试设置文件时,我测试的所有Async方法都包含在覆盖结果中并且适当地着色:

enter image description here

但是,当我包含.runsettings文件时,异步方法不再包含在Coverage结果中并保持未着色:

enter image description here

据我所知,.runsettings文件中没有任何内容可以忽略异步方法:

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

            <!-- Match assembly file paths: -->
            <ModulePaths>
              <Exclude>
                <ModulePath>.*xunit.*</ModulePath>
              </Exclude>
            </ModulePaths>
            <!-- Match attributes on any code element: -->
            <Attributes>
              <Exclude>
                <!-- Don't forget "Attribute" at the end of the name -->

                <Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
                <Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
                <Attribute>^System\.Runtime\.CompilerServices.CompilerGeneratedAttribute$</Attribute>
                <Attribute>^System\.CodeDom\.Compiler.GeneratedCodeAttribute$</Attribute>
                <Attribute>^System\.Diagnostics\.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
              </Exclude>
            </Attributes>

            <!-- We recommend you do not change the following values: -->
            <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
            <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
            <CollectFromChildProcesses>True</CollectFromChildProcesses>
            <CollectAspDotNet>False</CollectAspDotNet>

          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

我是否遗漏了.runsettings文件中的内容以使其正常工作?

1 个答案:

答案 0 :(得分:9)

结果

<Attribute>^System\.Runtime\.CompilerServices.CompilerGeneratedAttribute$</Attribute>

导致异步方法未包含在代码覆盖率中。