C# 如何向SonarQube添加单元测试覆盖率?使用Azure DevOps管道
我试图将代码覆盖率添加到sonarqube中,包括并执行测试,但覆盖率百分比为0.0 在我的管道中,我得到了“Prepare analysis on SonarQube”,并且在附加属性“sonar.cs.vscoveragexml.reportsPaths=***.coveragexml”中对项目密钥进行了很好的配置,但没有任何更改,我也尝试了不使用该属性 另一个步骤是“VsTest-testAssemblies”,其中我选择了我的单元测试,并选择了代码覆盖率启用框,还有两个步骤是“运行代码分析”和“发布质量门结果”。这两个步骤与默认步骤类似,我尝试增加超时,但没有任何更改 “VsTest-testAssemblies”中的输出日志为 在“运行代码分析”中C# 如何向SonarQube添加单元测试覆盖率?使用Azure DevOps管道,c#,unit-testing,azure-devops,sonarqube,code-coverage,C#,Unit Testing,Azure Devops,Sonarqube,Code Coverage,我试图将代码覆盖率添加到sonarqube中,包括并执行测试,但覆盖率百分比为0.0 在我的管道中,我得到了“Prepare analysis on SonarQube”,并且在附加属性“sonar.cs.vscoveragexml.reportsPaths=***.coveragexml”中对项目密钥进行了很好的配置,但没有任何更改,我也尝试了不使用该属性 另一个步骤是“VsTest-testAssemblies”,其中我选择了我的单元测试,并选择了代码覆盖率启用框,还有两个步骤是“运行代码分
最后,我发现了问题所在 当我添加以下内容时,它为我解决了问题:
<DebugType>Full</DebugType>
Full
在.csproj
中。奇怪的是,其他项目报告了一些没有这个属性的代码覆盖率,所以我认为我不需要它
因此,如果报告的覆盖率似乎为false,请尝试在csproj
中添加此属性
我在
警告中发现:代码覆盖率报告不包含所包含文件的任何覆盖率数据。有关故障排除提示,请参阅https://docs.sonarqube.org/x/CoBh
。你开始阅读链接文档并尝试其中的建议了吗?是的,我尝试插入类似于d:propertyKey=“path”的内容,但没有成功。我的尝试之一是/d:sonar.verbose=true/d:sonar.cs.vscoveragexml.reportspath=**/*
20:08:05.303 Fetching code coverage report information from TFS...
20:08:05.308 Attempting to locate a test results (.trx) file...
20:08:05.364 Looking for TRX files in: X:\VSTSWork\52\TestResults, X:\VSTSWork\52\s\TestResults
20:08:05.366 The following test results files were found: X:\VSTSWork\52\s\TestResults\PRO_2019-05-09_20_07_48.trx
20:08:05.433 The following code coverage attachments were found from the trx files: X:\VSTSWork\52\s\TestResults\PRO_2019-05-09_20_07_48\In\PRO\PRO 2019-05-09 20_06_39.coverage
WARNING: File 'C:\Users\pro\.nuget\packages\runtime.win-x64.microsoft.netcore.dotnethostpolicy\2.1.0\runtimes\win-x64\native\hostpolicy.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\runtime.win-x64.microsoft.netcore.dotnethostresolver\2.1.0\runtimes\win-x64\native\hostfxr.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\xunit.runner.visualstudio\2.3.1\build\netcoreapp1.0\xunit.runner.visualstudio.dotnetcore.testadapter.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\xunit.runner.visualstudio\2.3.1\build\netcoreapp1.0\xunit.runner.reporters.netcoreapp10.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\xunit.runner.visualstudio\2.3.1\build\netcoreapp1.0\xunit.runner.utility.netcoreapp10.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
Calling the SonarQube Scanner...
.
..
...
INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the Visual Studio coverage XML report X:\VSTSWork\52\.\s\TestResults\PRO_2019-05-09_20_07_48\In\PRO\PRO 2019-05-09 20_06_39.coveragexml
INFO: Adding this code coverage report to the cache for later reuse: X:\VSTSWork\52\.\s\TestResults\PRO_2019-05-09_20_07_48\In\PRO\PRO 2019-05-09 20_06_39.coveragexml
WARN: The Code Coverage report doesn't contain any coverage data for the included files. For troubleshooting hints, please refer to https://docs.sonarqube.org/x/CoBh
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=3701ms
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the Visual Studio Test Results file X:\VSTSWork\52\s\TestResults\PRO_2019-05-09_20_07_48.trx
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=64ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=363ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer (done) | time=0ms
INFO: 49 files had no CPD blocks
INFO: Calculating CPD for 128 files
INFO: CPD calculation finished
INFO: Analysis report generated in 7191ms, dir size=810 KB
INFO: Analysis reports compressed in 1207ms, zip size=501 KB
INFO: Analysis report uploaded in 89ms
<DebugType>Full</DebugType>