# Set up test coverage

With the test coverage analyzer, you can setup your CI systems to send metrics to DeepSource. An issue will be raised when lines are not covered or reachable during tests.

Before proceeding, please ensure that you've created an account on DeepSource, and have added "Test Coverage" analyzer when enabling analysis (for the repository you want to set up test coverage for).

In case, Test Coverage analyzer was not added, add the following to your .deepsource.toml:

name = "test-coverage"
enabled = true

Here's what you need to do in order to setup test coverage:

  1. After running your tests, generate the test coverage report.
  • For Python projects, this can be done using coverage xml (or with pytest-cov for pytest projects) - this would create an XML file coverage.xml with all the information we need for tracking your test coverage.
coverage xml
  • For Go projects, the -coverprofile option can be used to generate cover.out.
go test -coverprofile=cover.out
  1. Install DeepSource CLI - To facilitate easy reporting of test coverage reports, DeepSource's CLI client is used. Use the following command to download it:
curl https://deepsource.io/cli | sh
  1. Find the repository's DSN and save it in an environment variable named DEEPSOURCE_DSN. To find DSN for your repository, go to Dashboard > Select Repo > Repo Settings > Reporting > DSN.


A Data Source Name (DSN) is a unique identifier used by DeepSource's systems to identify the repository.

  1. Report Coverage - From the repository's root, execute the following command:
./bin/deepsource report --analyzer test-coverage --key $LANG --value-file $COVREPORT


Replace $LANG and $COVREPORT according to the following table:

Project Language $LANG $COVREPORT
Python python coverage.xml
Go go cover.out
Ruby ruby .resultset.json

# Tracking Coverage with CI

Last Updated: 9/29/2020, 7:15:36 AM