【问题标题】:Azure DevOps build don't fail when coverage is below target with dotnet test当覆盖率低于 dotnet 测试的目标时,Azure DevOps 构建不会失败
【发布时间】:2019-06-17 12:12:42
【问题描述】:

我在 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 : 总行覆盖率低于指定的 80 coverlet.msbuild.targets(41,5): error : 总分支覆盖率低于指定的 80 coverlet.msbuild .targets(41,5): error : 总方法覆盖率低于指定的 80

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

【问题讨论】:

  • 尝试在dottent测试任务中添加failOnStderr: true
  • 我尝试过,但没有成功。我认为此消息不被视为失败。
  • 在日志中消息是红色还是白色?
  • 在我的终结者控制台中,红色,但在 azure devops 控制台中,白色。

标签: asp.net-core azure-devops code-coverage azure-pipelines


【解决方案1】:

尝试使用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.*]"'

【讨论】:

  • 抱歉我迟到了,但是这个解决方案很好用,谢谢!我现在的问题是为覆盖标准(分支、语句、行等)设置不同的值,但这是另一个问题:)
  • @NelsonB​​aggio Great :) 你可以接受答案 :)
  • 知道如何在 AppVeyor 中使用相同的技术吗?
  • @JoyGeorgeKunjikkuru 我不知道:/ 我不熟悉 AppVeyor
  • @ShaykiAbramczyk,我得到它的工作是关于相同的博客文章joymonscode.blogspot.com/2020/02/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-18
  • 2020-10-05
  • 2022-07-26
  • 2021-05-20
  • 1970-01-01
  • 2022-11-11
相关资源
最近更新 更多