I created a PR in my public repository, I have added proper tests and everything. But sonar test says that the lines are not covered. The details are as follows:
ALM used: GitHub
CI system used GitHub Actions
Scanner command used when applicable (private details masked)
Hi! Thanks for taking out your time. I am not a 100% sure if I am following your steps correctly. So I need to cd into folder test/Twilio.test and then run the command
and then run the dotnet test command from root directory. Is that what you are suggesting? I am facing some error on my local. Maybe it’s because of dotnet version but anyways, just wanted to check I am following the right steps?
You should try to make coverage work locally before pushing the changes to your CI pipeline. Getting code coverage files is a bit complicated in .Net, and it is important to make sure the coverage files are created.
The next step is ensuring that the files are found and understood by the scanner for dotnet on your pipeline.
but how do I make sure that it is correctly generated in GitHub as well?
Please check the following on your pipeline logs
Make sure the coverage file is created in the dotnet test test/Twilio.Test/Twilio.Test.csproj part of the script. Note the location (file and foldername) of the coverage file.
Make sure the /d:sonar.cs.opencover.reportsPaths command line argument points to the file
In the end step, look for “coverage” in the logs and make sure the coverage file is found by the end step
You need to change your script so that /p:CoverletOutput=... argument and the /d:sonar.cs.opencover.reportsPaths=.. argument point to the same file.
The /p:CoverletOutput seems to be relative to the csproj file: test/Twilio.Test/Twilio.Test.csproj and /p:CoverletOutput=…/lcov results in test/lcov.opencover.xml /d:sonar.cs.opencover.reportsPaths= should probably be something like /d:sonar.cs.opencover.reportsPaths="test/lcov.opencover.xml"
Okay i have some progress. Once I have made the paths same, the code coverage is still 0% but now it is showing 22 lines uncovered while earlier it was showing 8 lines uncovered. I think I just need to figure out how exactly should I write tests to cover them?
According to the logs of the PR, the coverage report gets imported to SonarCloud:
The coverage summary looks suspicious, though:
It says “0%” coverage for the Twillo module. Please check locally if the coverage reported by coverlet is sensible. Please also follow the documentation for coverlet for trouble shooting.