Sonar cloud missing files for coverage

Below are the details of my issue -

  • ALM used (Azure DevOps)
  • CI system used (Azure DevOps)
  • Scanner command used when applicable (private details masked)
  • C#
  • Azure Functions

I do not have any errors but my code coverage is not showing right on sonarcloud, sonarcloud is not showing few files/folders which are present inside my codebase and these files/folders are not excluded anywhere.

It start showing all the file if I rename the parent folder, tried everything issue seems to be with sonarcloud and if I revert the parent folder name it will again stop showing few files

Hi,

Welcome to the community!

Does the original name have “test” in it? We try to be smart about not requiring that the tests themselves be covered by tests. So if your directory name made it look like the contents were test files, they would have been excluded by default.

 
HTH,
Ann

No , Original name was HttpTriggers and if I rename it to any thing else like HttpFunctions it will start capturing all the files

and if I revert back situation is same. Problem is its not even showing all the files

Hi,

They don’t show up in the UI at all? Could you share your analysis log?

Share the Scanner for .NET verbose logs

Add /d:"sonar.verbose=true" to the Scanner BEGIN step. Examples:

dotnet sonarscanner begin /k:"MyProject" /d:"sonar.verbose=true"
SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
- task: SonarCloudPrepare@3 # or SonarQubePrepare@3
    inputs:
      SonarCloud: 'sonarcloud'
      organization: 'foo'
      scannerMode: 'dotnet'
      projectKey: 'foo_sonar-scanning-someconsoleapp'
      projectName: 'sonar-scanning-someconsoleapp'
      extraProperties: |
        sonar.verbose=true

Please note that most of the relevant logging will happen during the END step, i.e. in SonarCloudAnalyze, SonarQubeAnalyze or Run Code Analysis.

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

Share the binlog

When investigating a performance issue, it is helpful to also have access to the binlog:

MsBuild.exe /p:reportanalyzer=true /bl:build.binlog

or

dotnet build /p:reportanalyzer=true /bl:build.binlog

The parameters for detailed logs and binlogs can be combined.

 
Thx,
Ann

whats the security measures?

Hi,

Feel free to redact the logs as necessary.

 
HTH,
Ann

Sonar logs

This image is from sonar showing only 14 files while application has 32

above mentioned app structure which has 32 files, there are many files which are there in logs but not in sonarcloud for ex - ERPDataFunction.cs, if you see this file exists in logs but not on sonarcloud and its part of code base as well

Hi,

Thanks for the screenshot. It’s very helpful!

It shows that you’re looking at Coverage on new code.

What those dashes for ContractExtension, Summary and so on are telling you is that there is no new code in those directories.

 
HTH,
Ann

but my question is why it is not showing all the files , you can see I have added two screenshots above

  1. Repository has 32 items in folder
  2. Sonarcloud only showing 14 items

one example is file ERPDataFunction.cs, it is there in code repo but now showing on sonarcloud.

I checked in sonarlogs i attached here, it has the file details as well

Hi,

Your UI screenshot is from a branch. Is this a long-lived branch or a short-lived branch? If you go to the branch homepage, what do you see?

 
Ann

How does this change the files to shown on sonarcloud - whether it is either short-lived/long-lived

anyways this is the screenshot

Hi,

Based on your screenshot, this is a short-lived branch. That means it only reports on new code. Code that hasn’t been changed won’t be included. That explains your missing files: they haven’t been changed so they’re not relevant to short-lived branch reporting.

If this is not what you intended, you may want to re-examine your long-lived branch pattern.

 
HTH,
Ann

Thanks Ann, you are a superhero. It was helpful. I was checking everything in short-lived branch first before merging my code in to long-lived branch

I was not aware of different behavior of short-lived and long-lived

Hi,

It sounds like you may be interested in PR analysis instead of short-lived branches. It analyzes what’s changed since the base branch and makes the results available both in SonarQube Cloud and in your DevOps platform, directly on your PR.

 
HTH,
Ann