No code-coverage reported

  • ALM used : Azure DevOps
  • CI system used : Azure DevOps
  • All of this is run inside of docker, I’ve tried both locally and through Azure DevOps Pipelines
  • Scanner command :
dotnet sonarscanner begin \
      /k:"<projectName>-opf" \
      /o:"<orgName>" \
      /d:sonar.token="${DOCKER_SONAR_TOKEN}" \
      /d:sonar.cs.opencover.reportsPaths=./**/coverage.xml \
      /d:sonar.branch.name="${GIT_BRANCH}" \
      /d:sonar.projectBaseDir="/src/<projectName>" \
      /d:sonar.verbose=true \
  • .NET C#
  • I’m unable to get any code-coverage to show up in any of my scans. I’ve tried so many different things I don’t remember them all.
#Start with sonar begin as shown, this is from my Dockerfile

RUN dotnet build "<projectName>.csproj" -c Release -o /app/build

RUN dotnet test /Test<projectName>/Test.<projectName>.csproj --collect:"XPlat Code 
Coverage"

FROM build AS publish
RUN dotnet publish "<projectName>.csproj" -c Release -o /app/publish

RUN dotnet sonarscanner end /d:sonar.token="${DOCKER_SONAR_TOKEN}"

This is running on a branch where there is no new code, I just want to get the test-coverage working before merging into main.

When looking at the step where the tests are run, I see that the tests get executed, and a report is generated, however this is not reflected in SonarCloud

I’m pretty sure there is a simple solution to this, but I need help seeing it! Thank you!

Hey there!

What do the logs say about importing code coverage?

I’ll make sure to include the docs for .NET Test Coverage just in case. :slight_smile:

Hi, thanks for your reply!

image

I’m not entirely sure what I am looking for, but here is what I’ve found.

I have a feeling it might be this:


Which means I need to get a better overview of the folder structure I think

I’ve come one step further, but I need some help figuring out what to do next.

#30 21.90 10:32:40.487 INFO: Sensor C# File Caching Sensor [csharpenterprise] (done) | time=25ms
#30 21.90 10:32:40.488 INFO: Sensor C# Tests Coverage Report Import [csharpenterprise]
#30 21.90 10:32:40.488 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir '/src/XXX/.' and file separator '/'.
#30 21.90 10:32:40.489 DEBUG: Pattern matcher extracted prefix/absolute path '/src/XXX/./coverage.xml' from the given pattern 'coverage.xml'.
#30 21.91 10:32:40.490 DEBUG: Pattern matcher returns a single file: '/src/XXX/./coverage.xml'.
#30 21.91 10:32:40.491 DEBUG: The current user dir is '/src/XXX'.
#30 21.91 10:32:40.491 INFO: Parsing the OpenCover report /src/XXX/./coverage.xml
#30 21.91 10:32:40.496 DEBUG: The file '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/NoAllocEnumerateExtensions.cs' is not indexed or does not have the supported language. Will skip this coverage entry. Verify sonar.sources in .sonarqube\out\sonar-project.properties.
#30 21.91 10:32:40.497 DEBUG: CoveredFile created: (ID '1', path '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/NoAllocEnumerateExtensions.cs', NO INDEXED PATH).
#30 21.91 10:32:40.498 DEBUG: The file '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/SimplePool.cs' is not indexed or does not have the supported language. Will skip this coverage entry. Verify sonar.sources in .sonarqube\out\sonar-project.properties.
#30 21.91 10:32:40.498 DEBUG: CoveredFile created: (ID '2', path '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/SimplePool.cs', NO INDEXED PATH).
#30 21.91 10:32:40.499 DEBUG: The file '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/StringBuilderPool.cs' is not indexed or does not have the supported language. Will skip this coverage entry. Verify sonar.sources in .sonarqube\out\sonar-project.properties.
#30 21.92 10:32:40.500 DEBUG: CoveredFile created: (ID '3', path '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/StringBuilderPool.cs', NO INDEXED PATH).
#30 21.92 10:32:40.501 DEBUG: The file '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/HashCodeCombiner.cs' is not indexed or does not have the supported language. Will skip this coverage entry. Verify sonar.sources in .sonarqube\out\sonar-project.properties.
#30 21.92 10:32:40.501 DEBUG: CoveredFile created: (ID '4', path '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/HashCodeCombiner.cs', NO INDEXED PATH).
#30 21.92 10:32:40.501 DEBUG: The file '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/CompatibilityCacheKey.cs' is not indexed or does not have the supported language. Will skip this coverage entry. Verify sonar.sources in .sonarqube\out\sonar-project.properties.
#30 21.92 10:32:40.501 DEBUG: CoveredFile created: (ID '5', path '/_/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/CompatibilityCacheKey.cs', NO INDEXED PATH).

And hundreds more of these entries.

I saw some other thread of there being an issue of code coverage not showing when there were 0 lines of code in a PR, but this isn’t a PR scan. It does however not have any code changes in it. Any help would be greatly apprecciated!

It looks like whatever coverage file is being picked up includes entires for, inexpclicably, the source code of vstest!

Have you confirmed that this coverage file actually contains entries pertaining to your source code?