当覆盖率低于 dotnet 测试的目标时,Azure DevOps 构建不会失败

Nel*_*gio 3 code-coverage azure-devops asp.net-core azure-pipelines

我在 Azure DevOps 中有一个用于 ASP.NET Core 应用程序的构建管道,并且希望将其与批准拉取请求的条件一起使用。

steps:
      - script: dotnet restore
        displayName: 'Run command: dotnet restore'

      - script: >
                dotnet test 
                /p:CollectCoverage=true 
                /p:CoverletOutputFormat=cobertura 
                /p:Threshold=80 
                /p:ThresholdStat=total 
                /p:Exclude="[*xunit.*]*"
        displayName: 'Run command: dotnet test'
Run Code Online (Sandbox Code Playgroud)

我希望当代码覆盖率(使用封面)未通过时,构建失败。但是,尽管验收标准未通过,但即使生成了日志消息,该步骤仍会成功运行。

coverlet.msbuild.targets(41,5): error : 总行覆盖率低于指定的 80 coverlet.msbuild.targets(41,5): error : 总分支覆盖率低于指定的 80 coverlet.msbuild.targets( 41,5): 错误:总方法覆盖率低于指定的 80

在这种情况下有可能强制失败吗?

Sha*_*zyk 8

DotNetCoreCLI@2尝试使用任务而不是简单的来运行测试script

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    commands: test
    projects: 'path/to/tests/projects'
    arguments: 'p:CollectCoverage=true
 /p:CoverletOutputFormat=cobertura /p:Threshold=80
 /p:ThresholdStat=total /p:Exclude="[*xunit.*]"'
Run Code Online (Sandbox Code Playgroud)