我已经开始使用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文件。如果有人可以在这件事上提供帮助,那将是非常有帮助的。预先非常感谢。
答案 0 :(得分: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