[SOLVED] How to ignore some files when generating test coverage with VSTest and reportgenerator tools on Azure pipelines

Issue

I have a problem that I have failed to resolve.

I have a .NET core project that I want to run tests and publish the test coverage on Azure Pipelines.

The problem is: I’m using EF to generate Migrations files. I want to ignore these files from test
but I can’t.

Anyone how to do add some arguments to the pipe-lines command to ignore these files? like –exclude Migrations/*.cs

Here is the job in my azure-pipelines.yaml

- job: Testing
  steps:
    - task: [email protected]
      displayName: 'Use .Net Core sdk 3.1.x'
      inputs:
        version: 3.1.x

    - task: [email protected]
      inputs:
        command: 'test'
        projects: '$(build.sourcesDirectory)/tests/*Tests/*.csproj'
        arguments: -c $(BuildConfiguration) --logger trx --collect:"XPlat Code Coverage" --settings:$(build.sourcesDirectory)/src/test.runsettings -- RunConfiguration.DisableAppDomain=true
      displayName: 'run tests'

    - task: [email protected]
      inputs:
        command: custom
        custom: tool
        arguments: install --tool-path . dotnet-reportgenerator-globaltool
      displayName: Install ReportGenerator tool

    - script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"
      displayName: Create reports
           
    - task: [email protected]
      displayName: 'Publish code coverage'
      inputs:
        codeCoverageTool: Cobertura
        summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml

Solution

You’re probably looking for -classfilters or -filefilters.
https://github.com/danielpalme/ReportGenerator

I use -classfilter like this, where Foo.Bar.* and Foo.Baz.* is the namespace i want to exclude in the report:

variables:
  ...

  classes-to-exclude-from-coverage: "-Foo.Bar.*;-Foo.Baz.*"

  ...

- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"HtmlInline_AzurePipelines;Cobertura;Badges" -assemblyfilters:"-xunit*;" -classfilters:'$(classes-to-exclude-from-coverage)'
  displayName: Create reports


Answered By – Henkolicious

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *