Start FreeLog in
SonarCloud | Enriching your analysis | Test coverage | Dart test coverage

Dart test coverage

On this page

SonarCloud supports the reporting of test coverage information as part of the analysis of your Dart project.

However, SonarCloud does not produce the coverage report itself. Instead, you'll need to set up the Dart coverage tool to produce an LCOV report as part of your build process, then configure your analysis to tell the SonarScanner where the report is located so that it can pick it up and send it to SonarCloud. The report will be displayed on your project dashboard along with the other analysis metrics.

Follow the in-product tutorial

After you import your repository, SonarCloud directs you to the onboarding tutorial specific to your CI. Follow the tutorial, and when asked What option best describes your build?, choose Other (for JS, TS, Go, Python, PHP, ...). When you're done with the tutorial, you should have a functioning CI-based analysis setup for your project. The next step is to adjust it to get coverage working.

Adjust your setup

To enable coverage for Dart, you need to:

  • Adjust your build process so that the coverage tool generates the report(s) just after your unit as part of the clean build required to run analysis.
  • Make sure that the coverage tool writes its report file to a defined path in the build environment.
  • Configure the scanning step of your build so that the scanner picks up the report file from that defined path.

Adding coverage to your build process

For Dart projects, SonarCloud supports LCOV reports. The location of the coverage report produced by the tool must be set in the associated analysis parameter sonar.dart.lcov.reportPaths

Before running tests with coverage, the coverage tool needs to be enabled by running:

dart pub global activate coverage

After enabling it, tests can be executed with coverage support by running:

dart pub global run coverage:test_with_coverage

To produce data for branch coverage, you can provide the --branch-coverage parameter to the coverage:test_with_coverage target. You'll find more information and options in the Dart coverage package documentation.


Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License