We have recently upgrade to 8.9.8 LTS from 7.x version. When running the analysis for C# projects we use a quality profile that has below two code coverage rules active and set to minimum of 65%. When the analysis runs we are noticing zero coverage on new code and the build is not failing. This was working before the upgrade. Please help.
Attached is the log. I do not see any errors with the analysis.
sonar-log.txt (889.6 KB)
I’m not sure why you felt the need to redact the word “coverage” from the logs… which made it difficult to comb through.
It looks like things are in order
2022-09-26T18:22:24.8295805Z 14:22:24.804 INFO: xxxxxxxxxx Report Statistics: 515 files, 279 main files, 279 main files with xxxxxxxxxx, 236 test files, 0 project excluded files, 0 other language files.
2022-09-26T18:22:24.8296353Z 14:22:24.804 INFO: Sensor C# Tests xxxxxxxxxx Report Import [csharp] (done) | time=719ms
2022-09-26T18:22:24.8296746Z 14:22:24.804 INFO: Sensor C# Unit Test Results Import [csharp]
What do you see the UI that indicates no coverage data being imported? Can you share a screenshot of your project dashboard?
Take note that the logs you shared are for a Pull Request Analysis
2022-09-26T18:22:26.9986432Z 14:22:26.992 INFO: ANALYSIS SUCCESSFUL, you can browse httpsmysonar/dashboard?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-Api&pullRequest=35791
2022-09-26T18:22:26.9987086Z 14:22:26.992 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
Above are the screenshots for the analysis and the coverage on new files
It looks like overall coverage is beign reported quite well (91.9%), but in the context of your pull requests there is no coverage on the lines changed (added/modified).
Are there tests written for this modified code, and is the coverage reflected in your code coverage report?
In this case the developer did not write any tests for the files in the PR. They expected the sonar check to fail as the code coverage rule is in place. Since the build did not fail after that they wrote tests and the subsequent PR build showed the coverage as 95%. So the coverage reports are fine (in the build) but the rules in sonar is not marking the PR build as failed.
In my case all PR are getting merged to master. Due to this PR builds are not failing but master builds are failing as code coverage rule is working in master builds.
Is your Quality Gate configured to fail on Coverage on New Code?
This is the quality gate configuration that was working before the upgrade on 7.9 version.
It looks like you need to add Coverage back in – because right now it’s configured not to fail on a lack of coverage.
Are you saying that the two rules in the quality profiles will not take effect for PR branches since the quality profile does not have code coverage rules defined ? Is this expected with the new 8.9.8 LTS version ? The below configuration in the rule was working before upgrade.