Search code examples
c#azure-functionsazure-pipelinescode-coveragecoverlet

Files generated during build time appearing on code coverage


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:

enter image description here

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


Solution

  • 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>