如何使用coverlet
and将方法从代码覆盖率报告中排除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