Test coverage
On this page
Test coverage reports and test execution reports are important metrics in assessing the quality of your code. Test coverage reports tell you what percentage of your code is covered by your test cases. Test execution reports tell you which tests have been run and their results.
SonarCloud itself does not calculate coverage. To include coverage results in your analysis, you must set up a third-party coverage tool and configure SonarCloud to import the results produced by that tool (see below). This feature is only available for CI-based analysis. It is not available for automatic analysis.
General guidelines
To begin with, you should already have set up CI-based analysis. That is, you should have the appropriate SonarScanner configured to perform code analysis as part of your build pipeline.
To enable coverage reporting, you must then do the following:
- Set up your coverage tool to run as part of your build pipeline before the SonarScanner analysis step.
- Configure the coverage tool so that the location and format of the output report files match what the SonarScanner expects.
- Configure the analysis parameters of the SonarScanner so that it can import the report files.
Now, on each build of your project, your coverage tool should perform its analysis and output its results to one or more files (usually one for test coverage and one for test execution). Then, the SonarScanner, as part of its analysis process, should import those files and send the results to SonarCloud.
Coverage support
SonarCloud directly supports the import of coverage data in formats native to a variety of tools for a variety of languages. It also supports the import of a generic format that can be used as a target for custom conversion of reports from tools that are not directly supported.
Detailed guides
Detailed guides for the following languages are provided in this section:
- Dart test coverage
- Java Test Coverage
- JavaScript/TypeScript Test Coverage
- .NET Test Coverage
- Python Test Coverage
- PHP Test Coverage
- C/C++/Objective-C Test Coverage
Generic format
See Generic test data for information on how the generic format works.
Test coverage parameters
See Test coverage parameters for a reference on all coverage-related analysis parameters.
Test execution reports
This section is about test coverage reports, that is, reports that describe the percentage of your code that is tested by your test suite during a build.
Test execution reports are a separate feature. These describe which tests within your tests suite are executed during a build. For details, see Test Execution Parameters.
Was this page helpful?