c# - 代码覆盖率和代码行数在 sonarqube 控制台中显示为 '-'

标签 c# azure sonarqube nunit azure-pipelines

我正在使用 azure devops 来运行测试并尝试将 sonarqube 与其集成。我面临的问题是,在 azure pipeline 的摘要部分中,我能够将代码覆盖率视为 22%,但在 sonarqube 控制台中我我只能将代码覆盖率视为“-”。当我在管道中运行“运行代码分析”任务时,我看到一条警告消息。 警告消息为 WARN: 代码覆盖率报告不包含所包含文件的任何覆盖率数据。 [请找到图片查看azure pipeline中显示的代码覆盖率][1]

这是点测试任务的 yaml

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
  command: test
  projects: '**/*Test*.csproj'
  arguments: '--configuration $(BuildConfiguration) --collect "Code coverage"  '
  workingDirectory: '$(System.DefaultWorkingDirectory)'

This is the yaml for copy files task that i am doing right after the dot test task
steps:
- task: CopyFiles@2
  displayName: 'Copy Files to: $(Common.TestResultsDirectory)'
  inputs:
    SourceFolder: '$(Agent.WorkFolder)\_temp'
    TargetFolder: '$(Common.TestResultsDirectory)'

Please find the yaml file for Prepare analysis on sonarqube task
displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: 'CDA-Sonarqube'
    projectKey: Test
    projectName: Test
    extraProperties: sonar.cs.nunit.reportsPaths

Any help is appreciated.


  [1]: /image/HbZfW.png

最佳答案

WARN: The Code Coverage report doesn't contain any coverage data for the included files.

故障排除提示,请参阅https://docs.sonarqube.org/x/CoBh ,.coverage文件将在sonarqube结束分析任务期间转换为coveragexml

Run Unit Tests and Save Results in file "NUnitResults.xml"

packages\NUnit.ConsoleRunner.3.7.0\tools \ nunit3-console.exe --result=NUnitResults.xml "NUnitTestProject1\bin\Debug\NUnitTestProject1.dll"

or, for older NUnit 2

"%ProgramFiles(x86)%\NUnit 2.6.4\bin \nunit-console.exe /result=NUnitResults.xml "NUnitTestProject1\bin\Debug\NUnitTestProject1.dll"

同时,VSTS extension documentation in "Analysing a .NET solution" 中解释了一种解决方法:在“其他属性”文本区域中,添加以下属性:

sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml

您还可以引用这些案例( case1case2 )了解详情。

这是一个blog关于使用 SonarQube 和 Azure DevOps 为基于 Dotnet Core 的应用程序配置代码覆盖率。

关于c# - 代码覆盖率和代码行数在 sonarqube 控制台中显示为 '-',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57385353/

相关文章:

c# - Marshal.SizeOf 和 sizeof 之间的区别,我只是不明白

asp.net - 配置 Azure Web 角色以在启动时启动应用程序域

.net - 调用 RunAndBlock 后是否可以将动态生成的函数绑定(bind)到 Azure WebJobs JobHost?

java - Sonar 圈复杂度规则问题 - 不鼓励使用多个 return 语句

sonarqube - 在 sonarqube 中 - 如何将问题导出到 MS-Excel

c# - 在 .NET 4.6.1 上使用 SignalR Core

c# - 如何在 C# 中处理 NaN 和无穷大值

c# - 在 Controller 上找不到公共(public)操作方法

c# - 移动 Azure 服务 C# .NET 后端补丁未更新

java - sonarQube 包装器已停止