unit-testing - 在 azure devops yaml 管道上使用 dotnet 测试收集代码覆盖率
问题描述
我已经尽我所能来解决这个问题。
我有几个基于 Azure DevOps Services 构建的新 .net core 3.1 或 .net standard 2 项目。我正在尝试为这些项目设置代码覆盖率,但我一无所获。
在本地运行测试时,我获得了成功并创建了代码覆盖率结果。
3/24/20 3:39 [jgust] [portChangesFromAggregateRepo ≡]
>: dotnet test .\Common.UnitTests\ --collect:"Code coverage"
Test run for C:\src\bio\lib\Common\src\Common.UnitTests\bin\Debug\netcoreapp2.2\Common.UnitTests.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Attachments:
C:\src\bio\lib\Common\src\Common.UnitTests\TestResults\74f826e4-4a46-46dd-9fe5-7fd17b8cee1c\2020-03-24.15_40_28.coverage
Test Run Successful.
Total tests: 794
Passed: 794
Total time: 19.3390 Seconds
但是,在 Azure DevOps 上运行此项目时,生成报告找不到收集器。
A total of 1 test files matched the specified pattern.
Data collection : Could not find data collector 'Code coverage'
Results File: d:\a\_temp\VssAdministrator_fv-az130_2020-03-24_20_53_07.trx
Test Run Successful.
Total tests: 794
Passed: 794
管道任务如下:
是的,我在这里使用 Windows 平台
关于为这些项目设置代码覆盖率集合,我缺少什么。
据我所知,我要把书里的一切都写得精疲力尽
另外,我正在使用描述的包版本:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
解决方案
您应该在 中指定测试项目的 csproj 文件的路径Path to project(s)
,并确保测试项目引用Microsoft.NET.Test.SDK版本 15.8.0 或更高版本
虽然指定.dll
文件的路径将使dotnet test
任务下的命令能够运行测试,但它不允许收集覆盖率数据。该操作需要.csproj
文件路径。
尝试使用
$(System.DefaultWorkingDirectory)\**\*${{ parameters.slnName }}*[T|t]est*.csproj
注意:这个规范应该使否定过时。
推荐阅读
- python - 我的代码有效;我的目标是将 pdf 解析为 excel 多页。我现在只能做一页
- java - 如何拆分列表中的字符串并使用逗号作为分隔符
- regex - 可以在 SAS 中组合正则表达式查询吗?
- firebase - Firebase 国际推送通知
- javascript - 将变量从 PHP 传递给 JS 检查是否为空
- python - 在一对多加入 pandas 中分配价值
- java - 将剧集添加到电视剧
- java - 如何在 SpringBoot 2.0.5 应用程序上启用 HTTPS
- r - 如何在 Plot_ly 中为 mesh3d 绘图添加自定义颜色索引?
- c# - 如何在我的 Windows 窗体应用程序 (Visual Studio) 中启用使用 TAB 按钮