代码覆盖率和代码行数在 sonarqube 控制台中显示为“-”

我正在使用 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]: https://i.stack.imgur.com/HbZfW.png


缥缈止盈
浏览 201回答 2
2回答

心有法竹

默认情况下测试结果文件位于temp文件夹中,尝试通过复制文件任务复制文件,然后.coverage文件将被分析并生成coveragexml文件。- task: CopyFiles@2  displayName: 'Copy Files to: $(build.sourcesdirectory)\TestResults'  inputs:    SourceFolder: '$(Agent.TempDirectory)'    TargetFolder: '$(build.sourcesdirectory)\TestResults'

潇潇雨雨

WARN: The Code Coverage report doesn't contain any coverage data for the included files.有关故障排除提示,.coverage 文件将在 sonarqube 结束分析任务期间转换为coveragexmlRun 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 扩展文档中的“分析 .NET 解决方案”中解释了一种解决方法:在“附加属性”文本区域中,添加以下属性:sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml
打开App,查看更多内容
随时随地看视频慕课网APP