# Dart test coverage

However, SonarQube Server does not produce the coverage report itself. Instead, you must set up a coverage tool to produce an [LCOV report](https://github.com/linux-test-project/lcov) as part of your build process configure your analysis to tell the SonarScanner where the report is located so that it can pick it up and send it to SonarQube Server, where it will be displayed on your project dashboard along with the other analysis metrics.

## Adjust your setup <a href="#adjust-your-setup" id="adjust-your-setup"></a>

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 <a href="#adding-coverage-to-your-build-process" id="adding-coverage-to-your-build-process"></a>

For Flutter or Dart projects, SonarQube Server supports [LCOV reports](https://github.com/linux-test-project/lcov). The location of the coverage report produced by the tool must be set in the associated analysis parameter `sonar.dart.lcov.reportPaths`.

Multiple options are available to generate coverage reports, depending on the type of project and the tools used to run test. For example:

* the [Flutter command-line tool](https://docs.flutter.dev/reference/flutter-cli), when dealing with Flutter projects
* the [Dart coverage package](https://pub.dev/documentation/coverage/latest/), when dealing with generic Dart projects

```dart
# example for a Flutter project
flutter test --coverage

# example for a Dart project
dart pub global activate coverage
dart pub global run coverage:test_with_coverage
```

To produce data for branch coverage when using the Dart coverage package, 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](https://pub.dev/documentation/coverage/latest/).

## Adding the coverage analysis parameter <a href="#adding-the-coverage-analysis-parameter" id="adding-the-coverage-analysis-parameter"></a>

The next step is to add `sonar.dart.lcov.reportPaths` to your analysis parameters. This parameter must be set to the path of the report file produced by your coverage tool. In this example, that path is set to the default. It is set in the `sonar-project.properties` file, located in the project root:

```properties
sonar.projectKey=<sonar-project-key>
...
sonar.dart.lcov.reportPaths=coverage/lcov.info
```

### Coverage parameters can be set in multiple places <a href="#coverage-parameters-can-be-set-in-multiple-places" id="coverage-parameters-can-be-set-in-multiple-places"></a>

As with other analysis parameters, `sonar.dart.lcov.reportPaths` can be set in multiple places:

* In the `sonar-project.properties` file, as mentioned above.
* On the command line of the scanner invocation using the `-D` or `--define` switch, for example, `sonar-scanner -Dsonar.dart.lcov.reportPaths=coverage/lcov.info`
* In the SonarQube Server interface under *Your Project* > **Project Settings** > **General Settings** > **Languages** > **Dart** > **Tests and Coverage** for project-level settings, and **Administration** > **Configuration** > **General Settings** > **Languages** > **Dart** > **Tests and Coverage** for global settings (applying to all projects).

## Related pages <a href="#related-pages" id="related-pages"></a>

* [test-coverage-parameters](https://docs.sonarsource.com/sonarqube-server/2025.1/analyzing-source-code/test-coverage/test-coverage-parameters "mention")
