我正在使用 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
您还可以引用这些案例( case1 、 case2 )了解详情。
这是一个blog关于使用 SonarQube 和 Azure DevOps 为基于 Dotnet Core 的应用程序配置代码覆盖率。
关于c# - 代码覆盖率和代码行数在 sonarqube 控制台中显示为 '-',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57385353/