Hii, .NET code coverage is not increasing/decresing the % after adding/reducing test cases
Hi,
41k lines to cover is a lot. You may need to add a lot of tests to shift the percentage. I suggest you concentrate instead on coverage on new code.
HTH,
Ann
Hi Ann,
Thank you for your suggestion — I really appreciate it. I wanted to let you know that even after commenting out all the test cases, the reported overall coverage percentage remains unchanged. Additionally, I’m not seeing the expected coverage results for the new code I’ve added. I also reviewed the new code documentation but wasn’t able to find a solution.
If you have any guidance on potential causes or areas I should investigate, it would be very helpful.
Hi,
First, this is a bit apples-and-oranges because your second screenshot shows Overall numbers. Second, why would you comment out all the test cases? Third, your Overall screenshot shows coverage “Not computed”, indicating that you stopped passing in coverage reports. This is moving backwards.
Ann
Yes, the screenshot shows the overall numbers, but the issue lies in the code coverage—it is neither increasing nor decreasing.
Secondly, I commented out all the test cases to verify whether the code coverage would drop to zero. If there are no test cases, the coverage should indeed be zero.
Lastly, I am unsure why the coverage reports have stopped being passed, and why it is moving backwards.
I am working on integrating a .NET application with Jenkins and SonarQube. While the Jenkins job builds successfully, the main issue is that code coverage remains static—it is neither increasing nor decreasing. Moreover, coverage data for newly added code is not being displayed at all.
Below is the script I am using:
‘’‘’‘’‘’‘’‘’
@echo off
REM === Basic Configuration ===
set SONAR_HOST_URL=http://190.168.12.345:9000
set SONAR_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXX
set PROJECT_DIR=C:\Users\Administrator\code-coverage\Plasma_AG_Internal\PlasmaAg_API
set COVERAGE_FILE=%PROJECT_DIR%\XUnitTest\coverage.xml
set SONAR_PROJECT_VERSION=1.0.%BUILD_NUMBER%
echo SONAR_PROJECT_VERSION is %SONAR_PROJECT_VERSION%
REM === Git Sync ===
cd “%PROJECT_DIR%”
git checkout cni_sonarqube
git fetch
git pull
REM === SonarQube Scan Start ===
dotnet sonarscanner begin ^
/k:“code-coverage” ^
/v:“%SONAR_PROJECT_VERSION%” ^
/d:sonar.cs.opencover.reportsPaths=“%COVERAGE_FILE%” ^
/d:sonar.host.url=“%SONAR_HOST_URL%” ^
/d:sonar.token=“%SONAR_TOKEN%”
REM === Run Tests with Coverage ===
coverlet “%PROJECT_DIR%\XUnitTest\bin\Debug\net6.0\XUnitTest.dll” ^
–target “dotnet” ^
–targetargs “test "%PROJECT_DIR%\XUnitTest" --no-build” ^
-f opencover ^
-o “%COVERAGE_FILE%”
REM === Build ===
dotnet build --no-incremental
REM === SonarQube Scan End ===
dotnet sonarscanner end /d:sonar.token=“%SONAR_TOKEN%”
echo Script completed.
‘’‘’‘’’
Hi,
Please give us the following version information:
- What is your SonarQube version?
- What is the version of the Scanner for .NET (MSBuild) that you are using?
- What version of MSBuild are you using?
And we’ll need the logs:
- please give us the verbose output of the scanner commands (please run
SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true
as the begin step, and please attach the output of theBEGIN
andEND
steps) - please give the output of running MSBuild in verbose mode (
/v:d
)
In addition, please see the following guides:
- Importing .NET Test Coverage into SonarQube Cloud (The code samples apply to SonarQube Server too)
- Configuring the import of code coverage for .NET
- Troubleshooting .NET code coverage import
Ann