SonarQube doesn't display code coverage but shows unit tests count

  • Version: Community Edition - Version 8.9.7
  • I’ve prepared .coverage file, codecoverage.xml and .trx file and publishing to sonarqube server but still code coverage is not getting displayed. It shows unit tests count properly.
  • I’ve tried certain online articles and it seems I have set up the reports path properly but somehow it’s not showing code coverage.

image

Below is the command I am running on aws machine.

SonarScanner.MSBuild.exe begin /k:"XXX" /v:"88" /n:XXX /d:sonar.host.url=XXX /d:sonar.login=XXX /d:sonar.skipPackageDesign=true /d:sonar.skipDesign=true /d:sonar.exclusions="*.xml" /d:sonar.verbose="true" /d:sonar.vbnet.vscoveragexml.reportsPaths="XXX\xyz.xml" /d:sonar.vbnet.vstest.reportsPaths="XXX\abc.trx"
 
MSBuild.exe projectname.sln /p:Configuration=Release /p:Platform="x86"
  
CodeCoverage.exe collect /output:***\code.coverage vstest.console.exe abc.dll /Settings:XXX\CodeCoverage.runsettings /logger:"trx;LogFileName=abc.trx" /Tests:SomeUnitTestMethods 

CodeCoverage.exe analyze /output:XXX\codecoverage.xml XXX\code.coverage
  
SonarScanner.MSBuild.exe end /d:sonar.login=XXX

Please help me to resolve the issue. Thanks in advance.

Hey there.

What do the logs from SonarScanner.MSBuild.exe end say? The relevant logs would start around here:

INFO: Sensor C# Tests Coverage Report Import [csharp]

2022-06-21T09:25:28.7742865Z 09:25:28.663 DEBUG: Sensors : CSS Rules -> JaCoCo XML Report Importer -> C# Project Type Information -> C# Properties -> JavaXmlSensor -> HTML -> XML Sensor -> VB.NET Project Type Information -> VB.NET Properties
2022-06-21T09:25:28.7743944Z 09:25:28.663 INFO: Sensor CSS Rules [cssfamily]
2022-06-21T09:25:28.7744751Z 09:25:28.663 INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
2022-06-21T09:25:28.7745242Z 09:25:28.663 INFO: Sensor CSS Rules [cssfamily] (done) | time=0ms
2022-06-21T09:25:28.7745684Z 09:25:28.663 INFO: Sensor JaCoCo XML Report Importer [jacoco]
2022-06-21T09:25:28.7746394Z 09:25:28.663 INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
2022-06-21T09:25:28.7747410Z 09:25:28.663 INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
2022-06-21T09:25:28.7748179Z 09:25:28.663 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
2022-06-21T09:25:28.7748872Z 09:25:28.663 INFO: Sensor C# Project Type Information [csharp]
2022-06-21T09:25:28.7749346Z 09:25:28.663 INFO: Sensor C# Project Type Information [csharp] (done) | time=0ms
2022-06-21T09:25:28.7750011Z 09:25:28.663 INFO: Sensor C# Properties [csharp]
2022-06-21T09:25:28.7750905Z 09:25:28.663 DEBUG: Project 'XXX:XXX:014DCBEC-A772-4B1E-AE43-68B44C8838DF': Property missing: 'sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project.
2022-06-21T09:25:28.7751956Z 09:25:28.663 DEBUG: Project 'XXX:XXX:014DCBEC-A772-4B1E-AE43-68B44C8838DF': No Roslyn issues reports have been found.
2022-06-21T09:25:28.7752751Z 09:25:28.663 INFO: Sensor C# Properties [csharp] (done) | time=0ms
2022-06-21T09:25:28.7753399Z 09:25:28.663 INFO: Sensor JavaXmlSensor [java]
2022-06-21T09:25:28.7754350Z 09:25:28.663 INFO: Sensor JavaXmlSensor [java] (done) | time=0ms
2022-06-21T09:25:28.7754775Z 09:25:28.663 INFO: Sensor HTML [web]
2022-06-21T09:25:28.7755387Z 09:25:28.678 INFO: Sensor HTML [web] (done) | time=15ms
2022-06-21T09:25:28.7756262Z 09:25:28.678 INFO: Sensor XML Sensor [xml]

Is this what you are asking to me share? I am using this property to share the report - sonar.vbnet.vscoveragexml.reportsPaths="" in command.

To be honest, I am new to this so not having much idea. Do I need to use any XML report importer?

Please guide. Thanks

I think you are asking for this log,

2022-06-21T09:25:56.7708193Z 09:25:56.724 INFO: Found 5 MSBuild VB.NET projects: 4 MAIN projects. 1 TEST project.
2022-06-21T09:25:56.7708617Z 09:25:56.724 INFO: Sensor VB.NET [vbnet] (done) | time=23811ms
2022-06-21T09:25:56.7709024Z 09:25:56.724 INFO: Sensor VB.NET Tests Coverage Report Import [vbnet]
2022-06-21T09:25:56.7709700Z 09:25:56.724 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir 'XXX\actions-runner-win-x64-2.287.1\_work\abc\.' and file separator '\'.
2022-06-21T09:25:56.7710839Z 09:25:56.724 DEBUG: Pattern matcher extracted prefix/absolute path

Did not find deterministic source path in 'D:\abc\_work\xyz\foldername\XXX\My Project\Settings.Designer.vb'. Will skip this coverage entry. Verify sonar.sources in .sonarqube\out\sonar-project.properties.

Is this something breaking?


2022-06-21T09:25:56.7884035Z 09:25:56.755 DEBUG: Skipping 'D:\actions-runner\actions-runner-win-x64-2.287.1\_work\aaa\aaa\aaa\aaa\aaa\AllFormsTester.vb' as it is a test file.

@Colin ,

I have also got this line. But the code is there so what could be wrong?

Also what is the meaning of this line?

2022-06-21T09:25:56.7904399Z 09:25:56.755 INFO: Coverage Report Statistics: 9 files, 0 main files, 0 main files with coverage, 9 test files, 0 project excluded files, 0 other language files.

It looks like all of the files found in your coverage report are being indexed as test files.

What version of the Scanner for .NET are you using?

I am using this version - MSBuild.SonarQube.Runner.Tool.4.8.0

Hey there.

Let me suggest that you upgrade to the latest version of the SonarScanner for .NET, v5.7.1. v4.8 was released almost 2.5 years ago.