Windows Presentation Foundation (WPF) c# code not showing code coverage % in SQ dashboard though unit tests are success in Azure Devops pipelines. Here I have attached files (Run Code Analysis & Publish Quality Gate Result). Please suggest us to get code coverage % in Sonarqube dashboard for successful unit tests.
HI Team, All the test cases are passed thru VSTest task, but Run code analysis not showing the code coverage in the result.
I have doubt in the below run code analysis log, “Analyzing coverage after aggregate found ‘0’ coverage files”----becoz of this may be code coverage is not coming. How could we resolve this. ?
“Adding this code coverage report to the cache for later reuse: F:\tfs_work_temp\TestResults\54ea57e9-26da-4d9b-bc00-f831addc4d9a\TFSBuild_LOUSSPWTP1129_2021-12-06.03_27_40.coveragexml
DEBUG: Analyzing coverage after aggregate found ‘0’ coverage files.
DEBUG: The total number of file count statistics is ‘0’.
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=0ms”
PFA logs of VSTest, Runcode analysis tasks, I tried the below options also, but no use.
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)\TestResults*.trx
sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)\TestResults*.coveragexml
Please review these and advise me to resolve this. thanks, Upendar
Hey @upendaravireni - just a note that the VSTest step in Azure DevOps pipelines does not produce a .coveragexml file but in fact produces a .coverage file.
I solved this with adding three steps to my pipeline:
Used a PowerShell step that leverages the coverage tool to find all .coverage files in a temp directory and convert them to .coveragexml file
Use the reportgenerator@5 step to convert the .coveragexml file to a SonarQube report.
Now in your SonarQubePrepare@4 step, you can consume the reports as follows: extraProperties: 'sonar.coverageReportPaths=$(Common.TestResultsDirectory)\SonarQube.xml'
PS: You could in theory skip the reportgenerator conversion and simply use extraProperties: 'sonar.cs.vscoveragexml.reportsPaths=$(Common.TestResultsDirectory)\*.coveragexml' instead.
Hi @KrylixZA , thanks for your reply.
We’re using nuget tool installer, artifactory nuget, prepare analysis configuration, MSbuild, VSTest, runcode analysis, publish quality gate result, publish build artifacts tasks in our Azure build pipeline. Now I’m able to find .trx file like below.
"Code coverage command line tool: I:\VS2019\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
Fetching code coverage report information from TFS…
Attempting to locate a test results (.trx) file…
Looking for TRX files in: F:\tfs_work\6110\TestResults, F:\tfs_work\6110\s\TestResults
The following test results files were found: F:\tfs_work\6110\s\TestResults\TFSBuild_LOUSSPWTP1135_2021-12-07_06_40_02.trx
Absolute path to coverage file:
F:\tfs_work\6110\s\TestResults\TFSBuild_LOUSSPWTP1135_2021-12-07_06_40_02\In\LOUSSPWTP1135\TFSBuild_LOUSSPWTP1135_2021-12-07.06_39_50.coverage
The following code coverage attachments were found from the trx files: F:\tfs_work\6110\s\TestResults\TFSBuild_LOUSSPWTP1135_2021-12-07_06_40_02\In\LOUSSPWTP1135\TFSBuild_LOUSSPWTP1135_2021-12-07.06_39_50.coverage"
But still getting same like earlier as
“Adding this code coverage report to the cache for later reuse: F:\tfs_work\6110.\s\TestResults\TFSBuild_LOUSSPWTP1135_2021-12-07_06_40_02\In\LOUSSPWTP1135\TFSBuild_LOUSSPWTP1135_2021-12-07.06_39_50.coveragexml
Analyzing coverage after aggregate found ‘0’ coverage files.
The total number of file count statistics is ‘0’.”
I understood as, statistics count shouldn’t be ‘0’. Need to find way to get the some values.
Have you tried to use the report generator to force conversion to a SonarQube report type and then use the additional properties in the SonarQube prepare step to look for that particular coverage report?
Eventually through a process of elimination there will be nothing left to fix