Track code coverage

Enabling Code Coverage will show you coverage metrics like Line Coverage, Branch Coverage, Condition Coverage, and, Composite Coverage. The Analyzer also looks at lines of code that were never executed by any tests and raises actionable issues for them.

Enable the Test Coverage Analyzer

Enable the Test Coverage Analyzer through the dashboard under Settings > Code Review, or optionally via a .deepsource.toml file by adding:

[[analyzers]]
name = "test-coverage"
enabled = true

Set up DEEPSOURCE_DSN environment variable

DSN is used to associate the coverage artifact to the repository. This needs to be configured before sending a coverage artifact for analysis.

To look up the DSN:

  • Go to the Settings page of the repository dashboard in DeepSource
  • Go to the Code Coverage Section
  • Click on Copy button to copy your DSN.

Once you get the DSN, please make sure you store it as an environment variable named DEEPSOURCE_DSN in your CI's environment.

Install DeepSource CLI

curl https://deepsource.com/cli | sh

This creates a bin directory in the current working directory with the deepsource executable inside it.

Report coverage

./bin/deepsource report --analyzer test-coverage --key <key> --value-file <path-to-coverage-report>

In the above command, <key> is the language for which you'd be sending the coverage report.

  • List of supported languages and coverage formats can be found on the Languages page.
  • Please refer to the CLI documentation for more on the report command.

Always run the CLI report command from the root of your repo. This ensures filepaths in the test reports are handled correctly.

The maximum allowed size for the coverage report file is 20 MB.

Next steps

  • CI provider guides — boilerplate config for Travis CI, Circle CI, GitHub Actions, GitLab CI, Heroku CI, and Azure Pipelines
  • Docker coverage — reporting coverage from inside or outside a Docker container
  • Multiple reports — merging partial coverage reports from multiple CI pipelines

On this page