SonarCloud Pipeline for Dart Language Showing 0% Code Coverage

SonarCloud Pipeline Issue: Code Coverage Not Detected in Flutter Mobile App (Dart)

ALM Used

  • Bitbucket Cloud

CI System Used

  • Bitbucket Cloud Pipelines

Scanner Command Used (bitbucket-pipeline.yml)

image: ghcr.io/cirruslabs/flutter:3.22.3

clone:
  depth: full

definitions:
  caches:
    sonar: ~/.sonar/cache

steps:
    - step: &generate-coverage
        name: Generate Coverage Report
        script:
          - flutter test --coverage

- step: &sonarcloud-security-scan
        name: SonarCloud Security Scan
        caches:
          - sonar
        script:
          - pipe: sonarsource/sonarcloud-scan:2.0.0
            variables:
              SONAR_TOKEN: $SONAR_TOKEN
              SONAR_PROJECT_KEY: "<Project-Name-Key>"
              SONAR_PROJECT_NAME: "<Project Name>"
              SONAR_SCANNER_OPTS: "-Dsonar.dart.lcov.reportPaths=coverage/lcov.info" 

Scanner Command Used (sonar-project.properties)

# Required metadata
sonar.projectKey=<Project-Name-Key>
sonar.organization=<Organization ID>

# Project details
sonar.projectName=<Project Name>
sonar.projectVersion=1.1.14+37
sonar.sourceEncoding=UTF-8

# Properties specific to the Flutter project
sonar.sources=lib
sonar.tests=test
sonar.exclusions=**/*.g.dart,**/*.freezed.dart,lib/app/core/shimmer_widget/**,lib/app/core/shimmer_widget/widgets/**,lib/app/modules/**/views/**
sonar.test.inclusions=**/*_test.dart

# Additional settings
sonar.flutter.enabled=true
sonar.language=dart

# Coverage settings (if you have coverage reports)
sonar.dart.lcov.reportPaths=coverage/lcov.info

Languages of the Repository

  • Dart

SonarCloud Project URL (if public)

  • N/A (Private project)

Issue Encountered

Despite having unit tests 70% nevertheless, the code coverage is being reported as 0% in SonarCloud. The tests are running successfully, and test results are being generated, but the coverage data is not reflected on the SonarCloud dashboard.

2 Likes

@Jochem_Toolenaar @georgi @quentin.chevrin @ganncamp could we kindly get some support here guys?

Hey @headWingman

Please do not tag users in threads they are not involved in. The FAQ is very clear on this.

I created a topic, when can I expect a response?

This is an open community with people volunteering their free time to provide assistance. We’re eager to contribute to the community, but you are not guaranteed a fast response.

Be patient

  • Wait a few days before bumping a topic that hasn’t received a response.
  • Do not @name mention individuals not involved in the topic.

Contribute as much as you expect to receive

  • Contribute to the community (helping others) as much as you expect to receive help.

It is not a replacement for more structured support

  • If you need SLAs, guaranteed response, privacy, SonarSource also offers Commercial Support.

You may think this bumps a thread up to the top of their list, but it does the exact opposite.

1 Like

Hello,

(posting that without having tested on my side but to try to unlock you)

Given that the sonarsource/sonarcloud-scan:2.0.0 relies on Docker Bitbucket, I believe you are facing the same problem as the one discussed here.

I suggest you try to configure your scan and import of coverage without using SonarSource/sonar cloud-scan:2.0.0 but instead call the sonar-scanner directly (get some inspiration from the post made by @Margarita_Nedzelska).

Alex

1 Like

Hello @headWingman,

Did you get a chance to try?
If this is still not working, can you share the logs?

Thanks
Alex

2 Likes


Screenshot 2024-09-25 at 7.52.49 AM

I’m running into an issue with my Bitbucket pipeline when trying to set up SonarCloud scanning. Specifically, I’m attempting to manually download and extract the Sonar Scanner CLI, but the pipeline throws an error:

+ unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
bash: unzip: command not found

To resolve this, I added the following command to install unzip before running the scanner:

apt-get update && apt-get install -y unzip

However, even with this addition, the pipeline still fails at the unzip command, indicating that it wasn’t installed correctly or perhaps there’s a misconfiguration somewhere in the environment.

Here is the relevant part of my pipeline script:

- step: &sonarcloud-security-scan
    name: SonarCloud Security Scan
    caches:
      - sonar
    script:
      - apt-get update && apt-get install -y unzip
      - export SONAR_SCANNER_VERSION=6.1.0.4477
      - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64
      - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip
      - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
      - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
      - export SONAR_SCANNER_OPTS="-server"
      - sonar-scanner \
        -Dsonar.organization=wingsfinltd \
        -Dsonar.projectKey=wingsfinltd_dhoni-mobile-app \
        -Dsonar.sources=. \
        -Dsonar.host.url=https://sonarcloud.io \
        -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info

I suspect that the base Docker image I’m using (sonarsource/sonarcloud-scan:2.0.0) might not have the unzip package available or there might be some issue with installing it in the pipeline environment.

Is there anything I’m missing in terms of setup or configuration that could help resolve this? I would greatly appreciate any guidance or suggestions on how to get the unzip command working or if there’s a better approach for handling the Sonar Scanner installation in a Bitbucket pipeline.

Thank you in advance!

1 Like

@Alexandre_Gigleux hey Alex, kindly have a look at the above please

If you’re using this image you don’t have to install sonar-scanner since it’s already there. You can just use. The reason why you might want to download the the scanner is when you’re using a different image that doesn’t have it.

I don’t know from where this property is coming but I don’t think it’s needed for our analysis.

I don’t see any issue with your configuration, so I will need to check the logs. Let me know if you can’t share the logs here, and I’ll open a private conversation.

Best,
Margarita

I have followed your instructions, but unfortunately, the issue persists. Could you kindly initiate a private conversation so I can share the logs with you?

@hasan @Margarita_Nedzelska any updates on this? It is needed urgently

Hey @headWingman

@Margarita_Nedzelska opened up a PM with @hasan and is waiting for logs.

This is a feature that is in early access. This is also a community forum. Please refer to our FAQ.

I created a topic, when can I expect a response?

This is an open community with people volunteering their free time to provide assistance. We’re eager to contribute to the community, but you are not guaranteed a fast response.

Be patient

  • Wait a few days before bumping a topic that hasn’t received a response.
  • Do not @name mention individuals not involved in the topic.

Contribute as much as you expect to receive

  • Contribute to the community (helping others) as much as you expect to receive help.

It is not a replacement for more structured support

  • If you need SLAs, guaranteed response, privacy, SonarSource also offers Commercial Support.

After looking at the logs (part of the logs that were shared), It seems to me that the analysis itself failed even before reaching the Dart analyzer.

From what I can see, the analysis failed due to the presence of C or C++ files. In order to analyze them, please, follow the documentation: Overview

If you only want to analyze Dart without C/C++/Objective-C files, you can follow the instructions in the error message:

`If you don’t want to analyze C/C++/Objective-C files, then prevent them from being analyzed by setting the following properties:
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

Try setting these properties and check what is the result.

Best,
Marharyta