ExcludeFromCodeCoverageAttribute 在 azuredevops 管道中不生效

ExcludeFromCodeCoverageAttribute does not take effect in azuredevops pipeline

我在 class 方法中添加了一些 [ExcludeFromCodeCoverage] 以获得正确的代码 coverage.It 在 visual studio 中运行良好,以便我可以获得正确的结果。 但是我们在 azuredevops 管道中使用 visual studio 测试,它不采用任何 effect.The 方法,其中包含此属性出现在代码覆盖率结果中。 我还在我的管道中指定了一个 CodeCoverage.runsettings 文件,我不清楚它会影响结果。

steps:
- task: VSTest@2
  displayName: 'VsTest - Test Function App Project'
  inputs:
    runSettingsFile: src/DWP.CDA.FunctionApp/DWP.CDA.FunctionApp.Test/CodeCoverage.runsettings
    codeCoverageEnabled: true
    diagnosticsEnabled: true

不确定您的 runsetting 文件是什么样的。但在我这边,一切正常,配置为 [ExcludeFromCodeCoverage] 的 类 被成功排除。

请尝试确保在您的运行设置文件中包含以下脚本:

 <Attributes>
   <Exclude>
     <Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
   </Exclude>
 </Attributes>

这是我在非排除和排除之间的比较结果: