Azure DevOps 代码覆盖率状态检查不应包含第三方 dll

问题描述 投票:0回答:1

我的 Azure Devops yaml 管道包含以下内容:

stages:
- stage: 'Build'
  displayName: 'Build, Test, Publish'
  jobs:
  - job: build
    displayName: Build
    steps:

    - task: NuGetAuthenticate@1 # needed to authenticate for private NuGet feed

    - script: |
        dotnet build --configuration Release

    - task: DotNetCoreCLI@2
      displayName: Test
      inputs:
        command: test
        projects: '**/*[Tt]ests/*.csproj'
        arguments: '--configuration release --collect "Code coverage" --no-build'

这会自动将“代码覆盖率状态检查”添加到我的拉取请求中。 list of PR checks 但是,令人失望的是覆盖率指标包括来自 NuGet 的第 3 方 dll,这使得我的代码覆盖率显得很低:

code coverage report

我怎样才能让它只报告我的代码的代码覆盖率?
azure-devops code-coverage
1个回答
0
投票

Pull Request中的代码覆盖率状态检查将全面反映相关Pipeline中的代码覆盖率结果。

我怎样才能让它只报告我的代码的代码覆盖率?

为了满足您的要求,您可以将
.runsettings

文件添加到您的项目中,并在 dotnet 测试任务中收集代码覆盖率时使用它来排除第三方 dll。

这是一个例子:

<?xml version="1.0" encoding="utf-8" ?> <RunSettings> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="Code Coverage"> <Configuration> <CodeCoverage> <ModulePaths> <Exclude> <ModulePath>moudle name1</ModulePath> <ModulePath>moudle name2</ModulePath> </Exclude> </ModulePaths> <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation> <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses> <CollectFromChildProcesses>True</CollectFromChildProcesses> <CollectAspDotNet>False</CollectAspDotNet> </CodeCoverage> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings> </RunSettings>

使用 dotnet 测试任务时,可以添加参数:
--settings filename.runsettings

例如:

- task: DotNetCoreCLI@2 displayName: Test inputs: command: test projects: '**/*[Tt]ests/*.csproj' arguments: '--configuration release --collect "Code coverage" --settings filename.runsettings --no-build'

有关更详细的信息,您可以参考此文档:
使用 .runsettings 文件配置单元测试

© www.soinside.com 2019 - 2024. All rights reserved.