We have integrated SonarCloud in our pipeline. Using Gitlab CI/CD YAML.
I am no Sonar expert, but I wanted to get the help from the community to figure out what’s causing this issue where Sonar is reporting 0 coverage on the MR, but the pipeline artifact for the unit tests we have in place is reporting that the tests cover the new lines of code added.
I will post some screenshots which helps in explaining what I am seeing.
Latest SonarCloud MR Scan Summary
Details of the Scan Summary for the Components (New Lines of Code)
Opening the File Reported with 0 Coverage
From the above screenshots, it is quite clear that newly added lines of code are reportedly not covered by any tests.
Initially, the metric for this specific function are correct as the unit tests (Jest) in our pipeline reports that indeed it was not covered.
The next screenshot I have though shows the progression where I added some tests specifically for the component and including the function highlighted from the previous screenshot.
Progression of pipeline unit test report
TO BE POSTED IN REPLY
File showing test coverage
TO BE POSTED IN REPLY
Given that I am able to verify via the unit test report artifacts that adding the tests in each stage covers portions of code added, it is fair to expect that those numbers in SonarCloud summary should also reflect this.
Our pipeline is showing that the unit tests run prior to Sonar (code quality test) executing:
Pipeline Visualized
TO BE POSTED IN REPLY
Unit Test entry in CI/CD Pipeline
TO BE POSTED IN REPLY
Sonar cloud configuration
TO BE POSTED IN REPLY
Test sequence execution
TO BE POSTED IN REPLY
I hope that someone can provide some insight on how to determine why this Sonar report is happening or if some configuration changes need to be made to ensure that the numbers will be reflective of the result of the unit test code coverage.
Thanks!