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

标签 asp.net-core azure-devops code-coverage 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'

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

coverlet.msbuild.targets(41,5): error : The total line coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total branch coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total method coverage is below the specified 80

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

最佳答案

尝试使用DotNetCoreCLI@2 任务而不是简单的脚本 运行测试:

- 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.*]"'

关于asp.net-core - 当 dotnet 测试的覆盖率低于目标时,Azure DevOps 构建不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56631066/

相关文章:

c# - 使用 Entity Framework 和 OData 查询的导航 DTO 属性

visual-studio - 在构建时生成 Swagger json

asp.net-mvc - Angular2 http post 无法捕获 Controller 操作

asp.net-mvc - 如何使用 .NET Core 中间件将 HTML 插入响应主体

azure - 使用变量组和模板的 Azure Pipelines 变量出现意外行为

php - 有没有办法让 PHPUnit 确定 @method 声明的代码覆盖率?

grails - IntelliJ 代码覆盖运行程序 - headless (headless)

azure-devops - 如何在不同环境中使用 Azure DevOps Pipeline 发布 ClickOnce 应用程序?

azure-devops - TFS Git Commit 消息验证

visual-studio - 在 VS 2008 中创建测试运行配置