簡體   English   中英

Sonarqube 顯示代碼覆蓋率為 0%,但顯示沒有通過測試

[英]Sonarqube showing code coverage as 0%, but shows the no of tests passed

我已經開始使用 Sonarqube 並且我已經設置了一個本地聲納服務器來測試它是如何工作的。

早些時候我使用/d:sonar.cs.vscoveragexml.reportsPaths並生成.coveragexml文件。 現在我正在嘗試使用MSTest命令生成.trx文件。
所以這些是我用來運行聲納分析的命令。

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 文件的確切命令。 如果有人可以在這件事上提供幫助,那將非常有幫助。 提前謝謝了。

SonarQube 文檔不能很好地解釋所有功能。

你需要做兩件事——

一種是使用 trx 文件執行單元測試用例,該文件將顯示單元測試用例的數量。
二是在分析代碼覆蓋率時,需要分析CodeCoverage.exe生成的.coveragexml文件。 為了解釋這一點 - 一旦執行單元測試,則 .trx 文件是記錄器文件,而 .coverage 文件具有覆蓋率數據。 這個.coverage 文件在被CodeCoverage.exe 分析后會生成.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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM