Coverage in Sonarqube is Still 0%

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

Hi, I have a golang application and already set the test with the output called coverage.out.

The content of coverage.out

?       agent_api/src   [no test files] 
ok      agent_api/src/apicalls  1.463s  coverage: 61.5% of statements 
?       agent_api/src/apicalls/ralali   [no test files] 
?       agent_api/src/constants [no test files] 
?       agent_api/src/controllers   [no test files] 
?       agent_api/src/controllers/cms   [no test files] 
?       agent_api/src/controllers/partner   [no test files] 
?       agent_api/src/gamification/contracts/repositories   [no test files] 
?       agent_api/src/gamification/controllers  [no test files] 
?       agent_api/src/gamification/helpers  [no test files] 
?       agent_api/src/gamification/middlewares  [no test files] 
?       agent_api/src/gamification/mock/repositories    [no test files] 
ok      agent_api/src/gamification/repositories 0.015s  coverage: 82.2% of statements 
ok      agent_api/src/gamification/services 0.007s  coverage: 85.5% of statements 
ok      agent_api/src/gamification/services/leaderboards    0.017s  coverage: 92.9% of statements 
ok      agent_api/src/helpers   0.012s  coverage: 9.1% of statements 
?       agent_api/src/middleware    [no test files] 
?       agent_api/src/redis [no test files] 
?       agent_api/src/redis/partner_redis   [no test files] 
?       agent_api/src/repository    [no test files] 
?       agent_api/src/repository/acl    [no test files] 
?       agent_api/src/repository/agent-domicile [no test files] 
?       agent_api/src/repository/agent-saldo    [no test files] 
?       agent_api/src/repository/agent_job_types    [no test files] 
?       agent_api/src/repository/agent_request_partner  [no test files] 
ok      agent_api/src/repository/agents 0.204s  coverage: 9.4% of statements 
?       agent_api/src/repository/app_versions   [no test files] 
ok      agent_api/src/repository/appfollow  0.021s  coverage: 70.3% of statements 
?       agent_api/src/repository/banks  [no test files] 
?       agent_api/src/repository/business_units [no test files] 
?       agent_api/src/repository/commission-adjustments [no test files] 
?       agent_api/src/repository/commissions    [no test files] 
ok      agent_api/src/repository/companies  0.014s  coverage: 17.1% of statements 
ok      agent_api/src/repository/digital_goods  0.222s  coverage: 63.3% of statements 
?       agent_api/src/repository/educations [no test files] 
?       agent_api/src/repository/hooks  [no test files] 
ok      agent_api/src/repository/job    0.008s  coverage: 0.0% of statements [no tests to run] 
?       agent_api/src/repository/job-category   [no test files] 
?       agent_api/src/repository/job-category-logs  [no test files] 
ok      agent_api/src/repository/job-result 0.020s  coverage: 5.0% of statements 
?       agent_api/src/repository/job-result-logs    [no test files] 
ok      agent_api/src/repository/job_apps   0.017s  coverage: 95.7% of statements 
?       agent_api/src/repository/job_price_config   [no test files] 
ok      agent_api/src/repository/locations  0.043s  coverage: 16.6% of statements 
?       agent_api/src/repository/logs   [no test files] 
ok      agent_api/src/repository/migrations 0.043s  coverage: 11.5% of statements 
ok      agent_api/src/repository/partner    0.004s  coverage: 0.0% of statements [no tests to run] 
?       agent_api/src/repository/payment_methods    [no test files] 
ok      agent_api/src/repository/ralali_auth    0.035s  coverage: 35.4% of statements 
?       agent_api/src/repository/referral_config_rules  [no test files] 
?       agent_api/src/repository/referral_rules [no test files] 
ok      agent_api/src/repository/referrals  0.023s  coverage: 12.8% of statements 
?       agent_api/src/repository/respondents    [no test files] 
ok      agent_api/src/repository/result 0.013s  coverage: 15.6% of statements 
?       agent_api/src/repository/roles  [no test files] 
?       agent_api/src/repository/saldo  [no test files] 
?       agent_api/src/repository/settlements    [no test files] 
?       agent_api/src/repository/user-fcm   [no test files] 
ok      agent_api/src/repository/user_roles 0.012s  coverage: 16.2% of statements 
ok      agent_api/src/repository/users  0.149s  coverage: 12.7% of statements 
?       agent_api/src/repository/voucher-history    [no test files] 
?       agent_api/src/repository/vouchers   [no test files] 
?       agent_api/src/repository/withdraw   [no test files] 
ok      agent_api/src/schedulers    0.071s  coverage: 21.2% of statements 
?       agent_api/src/services  [no test files] 
?       agent_api/src/services/acl  [no test files] 
ok      agent_api/src/services/agent-saldo  0.024s  coverage: 2.4% of statements 
?       agent_api/src/services/agent_job_types  [no test files] 
ok      agent_api/src/services/agents   0.042s  coverage: 9.3% of statements 
?       agent_api/src/services/app_versions [no test files] 
ok      agent_api/src/services/appfollow    1.342s  coverage: 82.1% of statements 
ok      agent_api/src/services/banks    0.004s  coverage: 30.8% of statements 
ok      agent_api/src/services/business_units   0.018s  coverage: 81.2% of statements 
?       agent_api/src/services/commission-adjustment    [no test files] 
ok      agent_api/src/services/companies    0.019s  coverage: 50.0% of statements 
ok      agent_api/src/services/digital_goods    0.180s  coverage: 21.2% of statements 
?       agent_api/src/services/educations   [no test files] 
?       agent_api/src/services/emails   [no test files] 
?       agent_api/src/services/hooks    [no test files] 
?       agent_api/src/services/images   [no test files] 
?       agent_api/src/services/insurance    [no test files] 
ok      agent_api/src/services/job  0.032s  coverage: 2.4% of statements 
?       agent_api/src/services/job-categories   [no test files] 
?       agent_api/src/services/job-result-logs  [no test files] 
ok      agent_api/src/services/job-results  0.028s  coverage: 6.1% of statements 
ok      agent_api/src/services/job_apps 0.005s  coverage: 0.0% of statements [no tests to run] 
ok      agent_api/src/services/locations    0.049s  coverage: 8.0% of statements 
ok      agent_api/src/services/migrations   0.038s  coverage: 2.4% of statements 
?       agent_api/src/services/partner  [no test files] 
?       agent_api/src/services/payment_methods  [no test files] 
ok      agent_api/src/services/ralali   0.013s  coverage: 0.0% of statements [no tests to run] 
?       agent_api/src/services/ralali_auth  [no test files] 
?       agent_api/src/services/referral_config_rules    [no test files] 
?       agent_api/src/services/referral_rules   [no test files] 
ok      agent_api/src/services/referrals    0.015s  coverage: 5.8% of statements 
?       agent_api/src/services/respondens   [no test files] 
?       agent_api/src/services/roles    [no test files] 
?       agent_api/src/services/saldo    [no test files] 
ok      agent_api/src/services/settlements  0.009s  coverage: 17.4% of statements 
?       agent_api/src/services/tax  [no test files] 
?       agent_api/src/services/user-fcm [no test files] 
?       agent_api/src/services/user_roles   [no test files] 
ok      agent_api/src/services/users    0.033s  coverage: 2.4% of statements 
?       agent_api/src/services/users/users_agent    [no test files] 
?       agent_api/src/services/voucher-history  [no test files] 
?       agent_api/src/services/vouchers [no test files] 
ok      agent_api/src/services/withdraw 0.022s  coverage: 2.2% of statements 
ok      agent_api/src/tests 0.050s  coverage: 0.0% of statements 
?       agent_api/src/third_party/appleboy/gin-jwt  [no test files] 
ok      agent_api/src/tools/pdf 0.209s  coverage: 97.0% of statements 

Then, I start scan with sonnar-scanner with command below:
./sonar-scanner -Dsonar.scm.disabled=True -Dsonar.go.coverage.reportPaths=/bin/coverage.out -Dsonar.projectKey=agent_api -Dproject.settings=../conf/ -X

I can see scan’s result in Sonarqube Instance, but the coverage still 0%

Hello @jaswenny,

Please have a look at the scanner logs, I assume that you will see something like this. (If not, can you provide the logs?)

INFO: Load coverage report from 'your/path'
ERROR: Coverage import failed: Invalid go coverage at line 2

The reason is that you are not providing the correct report, as you can see, coverage.out contains only a percentage, and not precise information about which line is covered or not.

The report should looks something like this:

mode: set
awesomeProject/main.go:5.13,6.10 1 1
awesomeProject/main.go:10.2,11.21 2 1
awesomeProject/main.go:6.11,8.3 0 1
awesomeProject/main.go:15.72,17.2 0 0

I generated it by using the command go test -coverprofile=coverage.out.

Hope this helps,


It works after I change the report format to be like yours. Thanks a lot!
If the project is in PHP and the report is generated in .xml, can sonar read the file?

Hi, I’m want to send the coverage result from PHP app and it failed (coverage is still 0)
The content of coverage.xml
Untitled.txt (283.4 KB)

I scan with command below
./sonar-scanner -Dsonar.scm.disabled=True -Donar.php.coverage.reportPaths=$CODEBUILD_SRC_DIR/inside_docker/coverage.xml -Dsonar.projectKey=api-orders -Dsonar.projectBaseDir=$CODEBUILD_SRC_DIR -Dproject.settings=…/conf/

Is there a problem with the format again?

Anyway, I scan with sonar-scanner in AWS Codebuild (same with my previous Go App).

Can someone answer this? I need to get this done. Thanks in advance

As noted in the documentation for Test Coverage and Execution, Clover XML-format coverage report files are accepted for sonar.php.coverage.reportPaths . I have no idea if your coverage file is formatted correctly, but with that info maybe you do. :slight_smile:

If you need help debugging analyses, it’s critical that you attach your scanner logs so we can provide meaningful help (instead of just guesses)

@Quentin @Colin

Hi, All
I run the scanner with this command :
./sonar-scanner/bin/sonar-scanner -Dsonar.scm.disabled=True -Dsonar.projectKey=api-orders -Dsonar.projectBaseDir=/home/ec2-user/api-orders -Dproject.settings=/sonar-scanner/conf/ -Dsonar.php.coverage.reportPaths=/home/ec2-user/api-orders/_reports/coverage.xml -Dsonar.php.tests.reportPath=/home/ec2-user/api-orders/_reports/junit-logfile.xml -Dsonar.exclusions=file:/home/ec2-user/api-orders/tests/,file:/home/ec2-user/api-orders/qa_test/

The coverage is still 0. Please help me to find out what’s the problem

Here is the log :

INFO: Scanner configuration file: /home/ec2-user/sonar-scanner/conf/

INFO: Project root configuration file: NONE

INFO: SonarQube Scanner

INFO: Java 11.0.3 AdoptOpenJDK (64-bit)

INFO: Linux 4.14.138-114.102.amzn2.x86_64 amd64

INFO: User cache: /home/ec2-user/.sonar/cache

INFO: SonarQube server 7.9.1

INFO: Default locale: "en_US", source code encoding: "UTF-8"

INFO: Load global settings

INFO: Load global settings (done) | time=174ms

INFO: Server id: FECAD177-AW3yS8iN_q5u-Fml-omt

INFO: User cache: /home/ec2-user/.sonar/cache

INFO: Load/download plugins

INFO: Load plugins index

INFO: Load plugins index (done) | time=62ms

INFO: Load/download plugins (done) | time=184ms

INFO: Process project properties

INFO: Execute project builders

INFO: Execute project builders (done) | time=6ms

INFO: Project key: api-orders

INFO: Base dir: /home/ec2-user/api-orders

INFO: Working dir: /home/ec2-user/api-orders/.scannerwork

INFO: Load project settings for component key: 'api-orders'

INFO: Load project settings for component key: 'api-orders' (done) | time=23ms

INFO: Load quality profiles

INFO: Load quality profiles (done) | time=51ms

INFO: Load active rules

INFO: Load active rules (done) | time=733ms

WARN: Using absolute path pattern is deprecated. Please use relative path instead of 'file:/home/ec2-user/api-orders/tests/**'

WARN: Using absolute path pattern is deprecated. Please use relative path instead of 'file:/home/ec2-user/api-orders/qa_test/**'

INFO: Indexing files...

INFO: Project configuration:

INFO: Excluded sources: file:/home/ec2-user/api-orders/tests/**, file:/home/ec2-user/api-orders/qa_test/**

WARN: Using absolute path pattern is deprecated. Please use relative path instead of 'file:/home/ec2-user/api-orders/tests/**'

WARN: Using absolute path pattern is deprecated. Please use relative path instead of 'file:/home/ec2-user/api-orders/qa_test/**'

INFO: Load project repositories

INFO: Load project repositories (done) | time=47ms

WARN: Invalid character encountered in file /home/ec2-user/api-orders/public/swagger-ui-assets/swagger-ui-bundle.js at line 71 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

WARN: Invalid character encountered in file /home/ec2-user/api-orders/public/swagger-ui-assets/swagger-ui-standalone-preset.js at line 13 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

INFO: 272 files indexed

INFO: 0 files ignored because of inclusion/exclusion patterns

INFO: Quality profile for php: Sonar way

INFO: Quality profile for web: Sonar way

INFO: Quality profile for xml: Sonar way

INFO: ------------- Run sensors on module api-orders

INFO: Load metrics repository

INFO: Load metrics repository (done) | time=37ms

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/home/ec2-user/.sonar/cache/866bb1adbf016ea515620f1aaa15ec53/sonar-javascript-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,

WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

INFO: Sensor JaCoCo XML Report Importer [jacoco]

INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=6ms

INFO: Sensor JavaXmlSensor [java]

INFO: 3 source files to be analyzed

INFO: 3/3 source files have been analyzed

INFO: Sensor JavaXmlSensor [java] (done) | time=1045ms

INFO: Sensor HTML [web]

INFO: Sensor HTML [web] (done) | time=706ms

INFO: Sensor XML Sensor [xml]

INFO: 3 source files to be analyzed

INFO: Sensor XML Sensor [xml] (done) | time=946ms

INFO: 3/3 source files have been analyzed

INFO: Sensor PHP sensor [php]

INFO: 248 source files to be analyzed

INFO: 185/248 files analyzed, current file: app/Modules/BusinessLogic/V4/Cart/QR/DeleteAllCartLogic.php

INFO: 248/248 source files have been analyzed

INFO: Analyzing PHPUnit test report: /home/ec2-user/api-orders/_reports/junit-logfile.xml

INFO: Analyzing PHPUnit coverage report: /home/ec2-user/api-orders/_reports/coverage.xml

WARN: Could not resolve 41 file paths in coverage.xml, first unresolved path: /usr/share/nginx/html/api-orders/app/Modules/BusinessLogic/V4/BusinessLogic.php

INFO: Sensor PHP sensor [php] (done) | time=15349ms

INFO: Sensor Analyzer for "php.ini" files [php]

INFO: Sensor Analyzer for "php.ini" files [php] (done) | time=8ms

INFO: ------------- Run sensors on project

INFO: Sensor Zero Coverage Sensor

INFO: Sensor Zero Coverage Sensor (done) | time=94ms

INFO: SCM Publisher is disabled

INFO: 21 files had no CPD blocks

INFO: Calculating CPD for 229 files

INFO: CPD calculation finished

INFO: Analysis report generated in 367ms, dir size=2 MB

INFO: Analysis report compressed in 710ms, zip size=889 KB

INFO: Analysis report uploaded in 159ms


INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report

INFO: More about the report processing at

INFO: Analysis total time: 25.955 s

INFO: ------------------------------------------------------------------------


INFO: ------------------------------------------------------------------------

INFO: Total time: 27.869s

INFO: Final Memory: 7M/30M
INFO: ------------------------------------------------------------------------

Hi, @Quentin @Colin can you help me?

Hi @jaswenny

Could you create a new thread with the problem you have for PHP project?
It’s hard to follow when several topics are handled in the same thread.

Also try to provide all required info to investigate the problem (project config, logs, report etc.).

Thank you