Obtaining SonarQube Unit Test Coverage Metrics Locally

  • SonarQube Enterprise EditionVersion 9.9 (build 65466), sonarqube-scanner - 3.0.1
  • I am trying to achieve - locally get coverage information based on SonarQube configuration.

I have been attempting to obtain coverage information on my local machine based on the remote SonarQube project configuration, following the execution of unit tests.

However, I have encountered a discrepancy between the metrics provided by Jest (the unit test framework I am using) and the metrics displayed in the SonarQube reports. This inconsistency has caused confusion among our development team.

Initially, I attempted to address this issue by including the “sonarqube-scanner” npm package in the dev dependencies of my project.
However, I found this approach to be somewhat excessive for my current needs. From my understanding, the “sonarqube-scanner” scans the code locally and then pushes it to the SonarQube server for analysis and reporting.
Unfortunately, the token I possess lacks the necessary permissions to export the report, rendering this solution unfeasible for my situation.

I need guidance on whether it is possible to leverage the “sonarqube-scanner” to scan my local code based on the SonarQube configuration present in the cloud for my specific project. Ideally,

I would like to obtain coverage metrics from the report locally without the need to push the code to the server.

Alternatively, I would greatly appreciate it if you could share an alternative approach or recommended method to obtain SonarQube coverage metrics locally, aligned with the SonarQube project configuration.

WARN: Unexpected result from TQS reporting web service (HTTP status 400 / Content: {"error":"Could not create TQS report","cause":"Project ***-portal does not exist or is not accessible for user artem***20862 (HTTP error 403)","detail":"***.tqs.sonar.service.WebServiceException: Project ***-portal does not 
exist or is not accessible for user artem-*** (HTTP error 403)\r\n\t at ***.tqs.sonar.service.SonarQubeApiClient.checkIsAuthorizedForProject(SonarQubeApiClient.java:62)\r\n\t at ***.tqs.sonar.service.TqsReportRequestHandler.handle(TqsReportRequestHandler.java:69)\r\n\t at org.sonar.server.ws.WebServiceEngine.execute(WebServiceEngine.java:111)\r\n..."})


Welcome to the community!

There are a few different topics here. I’ll try to address them, but if you have followup questions, I reserve the right to ask you to create new threads. We try to keep it to one topic per thread. Otherwise it can get messy, fast.

This blog post will probably help.

Analysis always “pushes the code to the server”. It’s hard to report on where your code is/is not covered without the code.

Sorry, that’s just not available.

This looks like an error from a 3rd-party plugin. You’ll need to contact its maintainers for help.