【问题标题】:Why dotnet test tool is not creating code coverage report?为什么 dotnet 测试工具不创建代码覆盖率报告?
【发布时间】:2019-11-02 08:01:42
【问题描述】:

我的项目结构如下:

.
├── Application
├── Application.Core
├── Application.Domain
├── Application.Tests
├── Application.IntegrationTests
└── README.md

运行测试的命令我使用以下输入:

dotnet test $folder.FullName -c Release --no-build /p:CoverletOutput='$root\coverage' /p:MergeWith='$root\coverage.json' /p:CoverletOutputFormat=opencover 

$folder 指向我的 Application.Tests 路径:C:\projects\coredemoapp\CoreDemoApp.Tests$rootC:\projects\coredemoapp\

所有测试都成功运行。但是,问题是没有创建coverage.jsoncoverage.opencover.xml 文件。

我也尝试通过以下命令直接使用coverlet

coverlet <path to test.dll> -
-target "dotnet" --targetargs "test --no-build" --merge-with $root\coverage.json --format opencover

,一切都在我的本地机器上运行,具有 dll 的显式路径。但是在使用以前的$folder.FullName 作为&lt;path to assembly&gt; 运行命令的情况下,coverlet 假定路径到 debug dll,而不是应该的 release 版本,并且失败。

Link to the full build script

【问题讨论】:

  • 至少部分解决方案是提前使用coverlet --targetargs 并将release参数传递给它:--targetargs "test -c Release --no-build"

标签: powershell dotnet-test coverlet


【解决方案1】:

基本上我忘了将coverlet msbuild NuGet package 添加到我的测试项目中。之后,使用以下命令一切正常:

dotnet test $folder.FullName -c Release --no-build /p:CollectCoverage=true /p:CoverletOutput=$root\coverage /p:CoverletOutputFormat=opencover

【讨论】:

  • 我认为参数应该是--targetargs "test [path to test project].csproj --no-build" 而不是--targetargs "test -c Release --no-build"
  • /p: 是做什么用的?我有点困惑
  • @ajr 与coverlet.msbuild 完美配合。奇怪的是 coverlet.collector 包含在一个新的测试项目中,而不是 coverlet.msbuild
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-03
  • 1970-01-01
  • 1970-01-01
  • 2012-01-07
  • 1970-01-01
  • 2019-09-19
  • 2019-09-02
相关资源
最近更新 更多