Reputation: 1613
I have updated my Azure Functions from in-proc .NET 6 to isolated .NET 8 and I noticed that my code coverage went down sharply. After checking the Cobertura report generated by Coverlet I noticed that two classes seem to be generated during build time that are being considered for the report. These files are GeneratedFunctionMetadataProvider and DirectFunctionExecutor. Is there a way to prevent them from being included on my build other than adding those namespaces to the p/:Exclude list?
Here is a picture of the report showing those files:
This is how my Azure Pipelines look like
- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests'
inputs:
command: test
projects: '**\MyProject.Test\*.csproj'
publishTestResults: false #Set to false to specify file name
arguments: '--configuration $(BuildConfiguration) --logger "trx;LogFileName=$(Build.SourcesDirectory)/UnitTests/TestResults.trx" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Threshold=75 /p:ThresholdType=line /p:Exclude="[*]MyProject.Model.*%2c[*]MyProject.DataAccess.*%2c[*]MyProject.Data.*%2c[*]MyProject.Infrastructure.Migrations.*"'
nobuild: true
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
displayName: 'Code Coverage Report Generator'
condition: succeededOrFailed()
inputs:
reports: '**\MyProject.Test\coverage.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)/CodeCoverage'
reporttypes: 'HtmlInline_AzurePipelines;Cobertura;Badges;SonarQube'
I am using the following packages for coverlet
coverlet.collector 6.0.0
coverlet.msbuild 6.0.0
Upvotes: 4
Views: 846
Reputation: 11
For us, the easiest solution was to ignore every .g.cs
(generated code) file when generating the report.
We prefer this solution over the others because this way we don't have to edit our .csproj files with poorly documented flags.
Update your Code Coverage Report Generator step to include filefilters
:
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
displayName: 'Code Coverage Report Generator'
condition: succeededOrFailed()
inputs:
reports: '**\MyProject.Test\coverage.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)/CodeCoverage'
reporttypes: 'HtmlInline_AzurePipelines;Cobertura;Badges;SonarQube'
filefilters: '-*.g.cs' # <-- Add this line
Upvotes: 1
Reputation: 26033
Try adding these two directives to your .csproj file and see if that prevents the creation of the files you mentioned:
<FunctionsEnableExecutorSourceGen>false</FunctionsEnableExecutorSourceGen>
<FunctionsEnableWorkerIndexing>false</FunctionsEnableWorkerIndexing>
Upvotes: 2