2

我已经开始使用 Sonarqube,并且我已经设置了一个本地声纳服务器来测试它是如何工作的。

早些时候我使用/d:sonar.cs.vscoveragexml.reportsPaths并生成了.coveragexml文件。现在我正在尝试使用命令生成.trx文件。 所以这些是我用来运行声纳分析的命令。MSTest

MSBuild.SonarQube.Runner.exe begin /k:"93ca937be91ab25536462fgdfg566915" /n:"Solution" /v:"1" /d:sonar.cs.vstest.reportsPaths="C:\SonarQube\Solution.trx"

MSBuild.exe "Solution.sln" /t:Rebuild /p:Configuration=Release

MSTest /testcontainer:.\SolutionTests\bin\Release\SolutionTests.dll /resultsfile:"C:\SonarQube\Solution.trx"

MSBuild.SonarQube.Runner.exe end

在命令提示符下运行所有​​这些命令后,代码覆盖率显示为 0%,测试运行次数显示为 22。 在此处输入图像描述

我是否缺少任何其他命令来获取代码覆盖率。我知道有一个类似下面的命令:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"C:\SonarQube\Solution.trx"

我找不到分析 .trx 文件的确切命令。如果有人可以在这件事上提供帮助,那将非常有帮助。提前谢谢了。

4

1 回答 1

0

SonarQube 文档不能很好地解释所有功能。

你需要做两件事——

一种是使用 trx 文件执行单元测试用例,该文件将显示单元测试用例的数量。
其次,在分析代码覆盖率时,需要分析 CodeCoverage.exe 生成的 .coveragexml 文件。为了解释这一点——一旦执行单元测试,.trx 文件就是记录器文件,.coverage 文件有覆盖数据。当 CodeCoverage.exe 分析这个 .coverage 文件时,它会生成 .coveragexml 文件,我们需要将其传递给 msbuild 的声纳扫描仪进行分析和生成报告。因此,您的命令行将如下所示 -

MSBuild.SonarQube.Runner.exe begin /k:"93ca937be91ab25536462fgdfg566915" /n:"Solution" /v:"1" /d:sonar.cs.vstest.reportsPaths="C:\SonarQube\*.trx" /d:sonar.cs.vscoveragexml.reportsPaths="C:\SonarQube\*.coveragexml"

MSBuild.exe "Solution.sln" /t:Rebuild /p:Configuration=Release

//now you should try to run test cases and get .coverage file. I am using vstest. Please check for your vstest.console.exe path as per your Visual Studio installation

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /EnableCodeCoverage "%CD%\SolutionTests\bin\Release\SolutionTests.dll" /ResultsDirectory:"%CD%" /Logger:trx
 
//now as .coverage file is there, we will analyze it and generate .coveragexml using CodeCoverage.exe

"C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"C:\SonarQube\VSCoverage.coveragexml" "<give here path for .coverage file"

MSBuild.SonarQube.Runner.exe end
于 2020-08-12T10:26:09.543 回答