Test Coverage is 0% for c# even after setup

After configuring the project in the SonarQube built the code and ran the below instructed commands but still i am seeing 0% coverage infact we have around 60+%

Code: c#
Version: .NET6
Sonar Edition: Developer / Community / Enterprise

Coverlet

dotnet sonarscanner begin /k:"<sonar-project-key>"
    /d:sonar.token="<sonar-token>"
    /d:sonar.cs.opencover.reportsPaths=coverage.xml
dotnet build --no-incremental
coverlet .<replaced with my project test dll path>
    --target "dotnet" 
    --targetargs "test --no-build"
    -f=opencover 
    -o="coverage.xml"
dotnet sonarscanner end /d:sonar.token="<sonar-token>"

during the scan I see this message
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

I am able to see the results in this format on the Command prompt but unable to see this results in sonar
Calculating coverage result…
Generating report ‘D:\sources\repos\xxxxxxxapi\coverage.xml’
±---------------------------------±-------±-------±-------+
| Module | Line | Branch | Method |
±---------------------------------±-------±-------±-------+
| APP.Accessors | 7.55% | 8.33% | 3.96% |
±---------------------------------±-------±-------±-------+
| APP.Common | 57.87% | 17.56% | 45% |
±---------------------------------±-------±-------±-------+

±--------±-------±-------±-------+
| | Line | Branch | Method |
±--------±-------±-------±-------+
| Total | 17.43% | 48.14% | 59.42% |
±--------±-------±-------±-------+
| Average | 37.27% | 46.32% | 40.7% |
±--------±-------±-------±-------+

Question is, am i missing any configuration?

2 Likes

I was able to resolve this with the following command lines:

dotnet sonarscanner begin /k:" AzureProjectToken " /d:sonar.host.url=http://127.0.0.1:9000  /d:sonar.token="token " /d:sonar.coverageReportPaths=".\sonarqubecoverage\SonarQube.xml"
dotnet build --no-incremental
dotnet test --no-build --collect:"XPlat Code Coverage"
reportgenerator "-reports:*\TestResults\*\coverage.cobertura.xml" "-targetdir:sonarqubecoverage" "-reporttypes:SonarQube"
dotnet sonarscanner end /d:sonar.token="token "

image
still need to figure out how to get the total number of tests.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.