在 azure devops 构建管道中,我有以下阶段。
- 准备声纳云分析
- dotnet 恢复
- dotnet 构建
- dotnet 测试
- 不要发布
- 复制测试文件..这用于将(*.trx *.xml)复制到相应的目录。
- 运行代码分析
- 发布质量门结果。
这里我的管道成功运行了测试,但没有提供代码覆盖率。代码覆盖率显示 0.00%
*.trx 文件正在所需路径上复制,我也尝试过使用 trx 文件的默认路径,但它在日志中给出以下消息。
错误消息
Post-processing started.
00:23:49.775 Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders.
00:23:49.995 Did not find any binary coverage files in the expected location.
00:23:49.995 Falling back on locating coverage files in the agent temp directory.
00:23:49.995 Searching for coverage files in D:\a\_temp
00:23:49.995 No coverage files found in the agent temp directory.
WARNING: The following projects do not have a valid ProjectGuid and were
not built using a valid solution (.sln) thus will be skipped from
analysis...
D:\a\1\s\Rost.API.Tests\Rost.API.Tests.csproj
我期望管道中的代码覆盖率,当前代码覆盖率显示 0.00%。
最佳答案
我可以向您确认几个问题吗?
Code coverage can be collected by adding --collect "Code coverage" option to the command line arguments. This is currently only available on the Windows platform.
- 如果在本地运行测试命令,代码覆盖率显示是否正确?
顺便说一句,SonarQube 需要一个有效的项目 GUID,但核心项目实际上并不使用它。建议在测试项目文件中添加 ProjectGUID。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- SonarQube requires a valid Project GUID but Core projects dont actually use this -->
<ProjectGuid>{9C99E491-F56E-4515-9F0B-D72A5207DB13}</ProjectGuid>
</PropertyGroup>
</Project>
关于Azure DevOps 声纳云代码覆盖率问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56814444/