SQ/Azure Dev Ops - CSharp - Code Coverage does not get picked up

Issue: Code Coverage does not get picked up even though the number of unit tests being run does get picked up.

Versions Used:

  • SonarQube Server: 8.3.1.34397
  • DevOps Agent Image: windows-latest
  • VSTest: 2.170.1
  • SonarScanner for MSBuild 4.10

Description:
After 2 weeks of investigation, I have confirmed that the tests are being run, the trx file is being generated and it does have the information regarding the number of tests being run. It also has a link to a .coverage file but I have not been able to verify the data in the .coverage file. All I can say is it’s got some data because it is about 2MB. I looked through the logs for the Run Analysis task and the Publish results task and confirmed that it’s picking up the data from the TRX file:

16:55:00.381 DEBUG: Parsed Visual Studio Test Times - duration: 359511.
16:55:00.429 DEBUG: Parsed Visual Studio Test Counters - total: 637, failed: 0, errors: 0, timeout: 0, aborted: 0, executed: 636.
16:55:00.437 INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=1418ms

And yet, Code Coverage for the project still shows up as 0% in SQ. Any suggestions or thoughts?

Hi @harivrdhn_vwac and welcome to our community.

Did you read the Code Coverage is not shown in the SonarCloud.io topic? Could you follow the advice given there to diagnose your problem?

You can also read this answer for more info and tips Scanner for MSBuild URL https://docs.sonarqube.org/x/CoB is broken

Hey Andrei,

Thank you for your reply.
I do not have the ability to trigger the said command as we just use the SonarQube tasks available on the MSBuild framework. But I am guessing the important part was to have logs set to verbose which I was able to accomplish.

Please find the logs attached.
SQ-Logs.txt (3.6 MB)

Do tell me if there’s more info you need as I have not been able to figure out a solution yet.

Regards,
Harivardhan

hi @harivrdhn_vwac

thanks for the verbose logs!

Line 257

2020-07-17T02:04:33.0686817Z sonar.projectBaseDir=D:\\a\\1\\s

Line 18811

2020-07-17T02:05:13.9675248Z 02:05:13.966 DEBUG: The current user dir is 'D:\a\1'.

The parsing of the coverage file starts at line 18812:

2020-07-17T02:05:13.9676872Z 02:05:13.966 INFO: Parsing the Visual Studio coverage XML report D:\a\1\.\TestResults\TestResults\VssAdministrator_fv-az176_2020-07-17_01_58_43\In\fv-az176\VssAdministrator_fv-az176 2020-07-17 01_58_31.coveragexml
2020-07-17T02:05:14.0787773Z 02:05:13.980 DEBUG: Skipping file with path 'D:\a\1\s\Shared\CosmosDb\DocumentIdFactory.cs' because it is not indexed or does not have the supported language.

We’d need to verify the contents of the Visual Studio coverage XML, to understand what it contains. From what I’ve seen in the logs, many files which are not in the projectBaseDir are mentioned in the coverage files (probably external projects).

Hey @Andrei_Epure,

I am not avle to upload a coveragexml file as it’s not supported by the UI here. How would you like me to share this?

Regards,
Harivardhan

The problem is that it doesn’t find any relevant information in the coverage file:

2020-07-17T02:05:12.9292257Z 02:05:12.925 INFO: Sensor C# Tests Coverage Report Import [csharp]
2020-07-17T02:05:12.9293360Z 02:05:12.925 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir 'D:\a\1\.' and file separator '\'.
2020-07-17T02:05:12.9294354Z 02:05:12.927 DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a\1\.' from the given pattern '**/*.coveragexml'.
2020-07-17T02:05:12.9407109Z 02:05:12.939 DEBUG: Gathering files for wildcardPattern '**/*.coveragexml'.
2020-07-17T02:05:13.9673831Z 02:05:13.966 DEBUG: Pattern matcher returns '1' files.
2020-07-17T02:05:13.9675248Z 02:05:13.966 DEBUG: The current user dir is 'D:\a\1'.
2020-07-17T02:05:13.9676872Z 02:05:13.966 INFO: Parsing the Visual Studio coverage XML report D:\a\1\.\TestResults\TestResults\VssAdministrator_fv-az176_2020-07-17_01_58_43\In\fv-az176\VssAdministrator_fv-az176 2020-07-17 01_58_31.coveragexml

...DEBUG logs saying it's skipping lots of files...

2020-07-17T02:05:14.4853687Z 02:05:14.234 DEBUG: Analyzing coverage after aggregate found '0' coverage files.
2020-07-17T02:05:14.4854216Z 02:05:14.234 DEBUG: The total number of file count statistics is '0'.
2020-07-17T02:05:14.4854744Z 02:05:14.234 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=1309ms

In the script running the commands, you should be able to print the contents of the coverage file.