Coverage

 

How to set coverage up

For the next steps, we assume you already have tests and coverage for your project. If you don't have coverage and need help, take a look at our article on how to generate coverage.


Projects can be configured to show code coverage reports directly in Codacy. Codacy reads the source coverage reports, converts them to a smaller JSON file and uploads them, showing all results integrated into your project's dashboard.

Project API Token


To setup coverage reporting you'll need a project API token. You can find it in your project settings 'Integrations' tab.

Jun-06-2017_14-30-02.gif
 

 

Token Security

You should keep your API token well protected, as it grants owner permissions to your projects. If you use CircleCI or Travis CI, you should use your token as an environment variable. (Don't put your keys in your configuration files, check your service settings on how to set environment variables)

 

Setting token as environment variable

export CODACY_PROJECT_TOKEN=%Project_Token%

(replacing %Project_Token% with your token)

 

Setup


Check detailed instructions on how to set up coverage in each reporter plugin.

 

POST API


If your language or build tool isn't supported yet, you can send the coverage data directly through the API. You can check the endpoint in the API Docs and an example of the JSON payload below.

{
  "total": 23,
  "fileReports": [
    {
      "filename": "src/Codacy/Coverage/Parser/CloverParser.php",
      "total": 54,
      "coverage": {
        "3": 3,
"5": 0, "7": 1 } } ] }

Note: In case the token was retrieved from the Project integrations tab, the header should be project_token. If it is an account token, the header should be api_token.

Also, note all coverable lines should be present on the "coverage" variable of the JSON payload. In the example, you can see that "5": 0, meaning that line 5 is not covered.

The Dashboard

The coverage dashboard only shows coverage values if the most recent commit has a coverage report. We do this because one commit can easily change the size or number of files on the project and even remove some of the files that have coverage information.

Instead of showing incorrect information based on an outdated report, we remove the information on the dashboard making sure our users aren't getting any incorrect information from Codacy.

 
SEE ALSO
 

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.