【发布时间】:2019-10-21 20:40:01
【问题描述】:
我已经使用“.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/ 实现了其中描述的 powershell 脚本,但我仍然没有在 SonarCloud 中得到任何代码覆盖
我尝试使用此处描述的床单,但仍然没有乐趣 https://gunnarpeipman.com/aspnet/azure-devops-code-coverage/
我的管道包含以下任务
- .NET Core - 恢复
- 准备分析配置
- .NET Core - 构建
- .NET Core - 测试
- 运行代码分析
- 发布质量门结果
我的测试任务已配置:
参数:--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.
【问题讨论】:
-
你能在当地用被单覆盖吗?如果是这样,我会尝试放置一个覆盖步骤并生成一个 lcov 文件以供 Sonar 收集。此外,如果您构建项目而不是整个解决方案,Sonar 在 csproj 中需要一个 ProjectGuid 标签,如您在此处看到的:docs.sonarqube.org/display/SCAN/…
-
我确实设置了 ProjectsGuids。当我在测试任务中实现 Coverlet 时,我确实在测试任务的控制台中显示了覆盖结果,并说它发布了这些结果,但我无法让 SonarCloud 获取它们(在控制台中它说它找不到他们)。无论我设置什么配置,它们都会发布到 temp 文件夹,SonarCloud 总是在 testresults 文件夹中查找。
标签: .net-core azure-devops code-coverage sonarcloud