在 Azure 管道上使用 VSTest 和报告生成器工具生成测试覆盖率时如何忽略某些文件

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

我有一个未能解决的问题。

我有一个 .NET 核心项目,我想 运行 测试并在 Azure Pipelines 上发布测试覆盖率。

问题是:我正在使用 EF 生成迁移文件。我想忽略测试中的这些文件 但我不能。

有人如何向管道命令添加一些参数以忽略这些文件?像 --exclude Migrations/*.cs

这是我天蓝色的工作-pipelines.yaml

- job: Testing
  steps:
    - task: UseDotNet@2
      displayName: 'Use .Net Core sdk 3.1.x'
      inputs:
        version: 3.1.x

    - task: DotNetCoreCLI@2
      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: DotNetCoreCLI@2
      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: PublishCodeCoverageResults@1
      displayName: 'Publish code coverage'
      inputs:
        codeCoverageTool: Cobertura
        summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml

您可能正在寻找 -classfilters-filefiltershttps://github.com/danielpalme/ReportGenerator

我这样使用 -classfilter,其中 Foo.Bar.*Foo.Baz.* 是我要在报告中排除的命名空间:

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