Kevin YANG
Kevin YANG

Reputation: 441

ExcludeFromCodeCoverageAttribute does not take effect in azuredevops pipeline

I add some [ExcludeFromCodeCoverage] in my class method in order to get the proper code coverage.It works well in visual studio so that I can get the right results. But we I use a visual studio test in azuredevops pipeline,It does not take any effect.The method which include this attribute appears in Code Coverage result. I also specify a CodeCoverage.runsettings file in my pipeline,I'm not clear it will effect the result.

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

Upvotes: 0

Views: 3174

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 19016

Not sure what's your runsetting files look like. But on my side, everything work fine and the classes which configured with [ExcludeFromCodeCoverage] are excluded successfully.

Please try with ensuring below script in your runsetting file:

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

Here is my compared result between non-exclude and excluded:

enter image description here

Upvotes: 2

Related Questions