被单测试覆盖率:错误使用阈值

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

我已经以这种方式配置了我的.net代码的封面分析:

  dotnet test \
    /p:CollectCoverage=true \
    /p:CoverletOutputFormat=cobertura \
    /p:Threshold=80 \
    /p:Exclude=[*]*.Program%2c[*]*.Controllers.*%2c[*]*.Models.*

Threshold
80,但是当我运行上面的脚本时,我发现即使阈值大于 80,它也会失败,例如这里:

Passed!  - Failed:     0, Passed:     2, Skipped:     0, Total:     2, Duration: 9 ms - ReactApp.Server.Tests.dll (net6.0)

Calculating coverage result...
  Generating report 'c:\..\ReactApp.Server.Tests\coverage.cobertura.xml'

+-----------------+------+--------+--------+
| Module          | Line | Branch | Method |
+-----------------+------+--------+--------+
| ReactApp.Server | 85%  | 50%    | 83.33% |
+-----------------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 85%  | 50%    | 83.33% |
+---------+------+--------+--------+
| Average | 85%  | 50%    | 83.33% |
+---------+------+--------+--------+

不知道为什么?任何帮助将不胜感激。

c# .net unit-testing code-coverage coverlet
1个回答
0
投票

设置单个值需要所有三个度量(行、分支和方法)都高于该值。由于分支覆盖率小于 80,因此失败。

要按度量分割覆盖范围,您需要像这样设置值的格式:

/p:Threshold=80,50,80

否则,您需要添加更多测试以使您的branch覆盖率达到>= 80%。

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