Tra*_*thy 6 code-coverage .net-core azure-devops sonarcloud
我已经使用“.NET Core with SonarCloud”模板在 Azure Devops 中为我的 .NET Core 项目设置了管道。当我构建时,分析会在 SonarCloud 中运行,但代码覆盖率为 0%(我的解决方案中有测试)。
无论我对构建进行什么配置调整,我都无法使代码覆盖率正常工作。
我错过了什么?
我遇到了这篇文章和https://dejanstojanovic.net/aspnet/2019/may/publishing-code-analysis-to-sonarcloud-from-azure-build-pipeline/ //dejanstojanovic.net/aspnet/2019/may/publishing-code-analysis-to-sonarcloud-from-azure-build-pipeline/ 实现了其中描述的powershell脚本,但我仍然没有SonarCloud 中的代码覆盖率
我尝试使用这里描述的床罩,但仍然没有乐趣 https://gunnarpeipman.com/aspnet/azure-devops-code-coverage/
我的管道由以下任务组成
我的测试任务是这样配置的:
参数: --configuration $(BuildConfiguration)
发布测试结果和代码覆盖率 - 选中
在运行代码分析任务的控制台中,我得到:
10:43:54.7 Fetching code coverage report information from TFS...
10:43:54.702 Attempting to locate a test results (.trx) file...
10:43:54.753 Looking for TRX files in: C:\\TFSBuilds\\TJPYHG04-GHJ01\\_work\\475\\TestResults
10:43:54.755 No test results files found
10:43:54.81 Did not find any binary coverage files in the expected location.
10:43:54.811 Falling back on locating coverage files in the agent temp directory.
10:43:54.812 Searching for coverage files in C:\\TFSBuilds\\TJPYHG04-GHJ01\\_work\\_temp
10:43:54.814 No coverage files found in the agent temp directory.
Run Code Online (Sandbox Code Playgroud)
ric*_*ick 12
希望这个答案仍然与您相关。
最近我和你有类似的问题,我也在使用 Azure DevOps 来解决我的问题。
我就是这样解决的。
步骤 1 - 将目录更改为单元测试子文件夹(与单元测试 .csproj 文件相同)并运行以下 dotnet 命令。
dotnet add package coverlet.msbuild
Run Code Online (Sandbox Code Playgroud)
第 2 步 - 将以下内容添加到 SonarCloudPrepare 任务附加属性或直接附加到 yml 文件中(如果您使用的是 yml 而不是经典编辑器)
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
Run Code Online (Sandbox Code Playgroud)
该目录由您选择配置。
或者,您也可以在您的sonar-project.properties存储库中创建一个名为的文件,并将所有相关的 SonarCloud 属性存储在其中。
第 3 步 - 将以下内容添加到您的 dotnet 测试任务中
- task: DotNetCoreCLI@2
inputs:
command: 'test'
arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx'
testRunTitle: 'dotnet test'
Run Code Online (Sandbox Code Playgroud)
您可能会注意到“发布测试结果和代码覆盖率”有一个复选框,但我仍然更喜欢使用/p:CollectCoverage=true.
您也可以在本地测试以运行该dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx命令,coverage.opencover.xml并将在您的单元测试文件夹中生成。
有关更多参数及其说明,请参阅参考文献 2 和 3。
旁注:如果你做任何声纳测试包括性能,注意Sonar.Tests和Sonar.Test.Inclusions他们的测试(S)是不同的。哈哈
参考:
希望这可以帮助 :)
无法从 Azure Devops .NET 核心构建获取 SonarCloud 中的代码覆盖率
此问题可能是由于最近更改了 vstest 输出路径引起的:
vstest覆盖率文件的输出路径从
D:\a\1\s\TestResults\...变为D:\a\_temp\...
这破坏了管道中的后续脚本(例如,codecoverage.exe 转换为 xml,然后导入到 sonarqube)。
Microsoft 建议使用其余 API 检查测试工件并将其重新下载到构建代理。
有关此问题的更多调查,您可以检查线程Azure DevOps (VSTS) 扩展不再自动导入覆盖率和单元测试以进行问题跟踪。
幸运的是,SonarSourcer 团队刚刚发布了新版本的 SonarQube (v4.6.3) 和 SonarCloud (v1.6.3) 扩展来解决覆盖问题和回归问题。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
5576 次 |
| 最近记录: |