3

如何使用coverletand将方法从代码覆盖率报告中排除reportgenerator.runsettings按预期排除整个命名空间,但使用[ExcludeFromCodeCoverage]属性排除整个文件,而不仅仅是目标方法。有关我尝试过的内容,请参阅下面的评论.runsettings

相关.runsettings线路:

  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector>
        <Configuration>
          <Format>lcov</Format>
          <Include>[*]*</Include>
          <Exclude> 
             <!-- excluded namespaces -->
          </Exclude>
          <!-- excludes entire file from coverage --> 
          <ExcludeByAttribute>Obsolete, GeneratedCodeAttribute, CompilerGeneratedAttribute,ExcludeFromCodeCoverage</ExcludeByAttribute>
          <!-- included & reported as uncovered --> 
          <ExcludeByAttribute> ExcludeFromCodeCoverageAttribute </ExcludeByAttribute>
          <SingleHit>true</SingleHit>
          <UseSourceLink>true</UseSourceLink>
          <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
          <!-- included and reported as uncovered -->
          <CodeCoverage>
            <Attributes>
              <Exclude>
                <Attribute> ^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
              </Exclude>
            </Attributes>
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>

更新:这似乎是最近解决的问题coverlet。更新解决了这个问题。https://github.com/coverlet-coverage/coverlet/issues/809

4

1 回答 1

6

只需应用于[ExcludeFromCodeCoverage]方法而不是类。

于 2020-07-15T17:12:58.553 回答