Generating code coverage metrics
Code Coverage tells you how much of your application is tested.
CircleCI provides a number of different options for code coverage reporting, using built-in CircleCI features combined with open source libraries, or using partners.
See coverage in CircleCI
It’s straightforward to see simple coverage results from your build. Simply add a coverage library to your project, and configure it to write the results out to CircleCI’s artifacts directory. CircleCI will upload coverage results and make them visible as part of your build.
Adding and configuring a coverage library
In Ruby 1.9, you add the simplecov gem and configure your test suite to add code coverage.
In your Gemfile, add the
gem 'simplecov', :require => false, :group => :test
or in your test suite’s startup hooks, initialize
require 'simplecov' # save to CircleCI's artifacts directory if we're on CircleCI if ENV['CIRCLE_ARTIFACTS'] dir = File.join(ENV['CIRCLE_ARTIFACTS'], "coverage") SimpleCov.coverage_dir(dir) end SimpleCov.start
The simplecov README has more details.
Python, Node, Java, PHP, etc
We’re working on a guide for other languages. In the meantime, add your coverage library of choice. Options include:
- coverage for python
- node-coverage, blanket.js, jscoverage or istanbul for Node
- php-code-coverage or Atoum for PHP
gcovfor C or C++.
Configure your library to save results in the directory specified by the CIRCLE_ARTIFACTS environment variable. Alternatively, add a test.post command to copy your artifacts into the artifacts directory.
Seeing the results in the CircleCI UI
We will upload your coverage files, which will allow you view them from the “Artifacts” tab on the build page:
You can also get them via the CircleCI API.
And then of course, by viewing the generated HTML, you can see beautifully rendered HTML in the UI.
Using a Code Coverage service
You can easily send coverage results from CircleCI to a number of external code quality services:
If you’re a Codecov customer, integration with CircleCI can be as easy as
test: post: - bash <(curl -s https://codecov.io/bash)
No upload token is required for open source repositories.
Codecov’s Bash uploader detects all coverage reports from all languages and details for the CircleCI build to create a single, cohesive coverage report. Codecov will automatically handle the merging of coverage stats in parallel builds.
For more information find an example of your language here: https://github.com/codecov?query=example
Coveralls will automatically handle the merging of coverage stats in parallel builds.
If you’re a Code Climate customer, follow the instructions under
Repo Settings -> Test Coverage
from your repo on the Code Climate site.
You’ll need to add your
CODECLIMATE_REPO_TOKEN to your CircleCI
Code Climate does not currently support CircleCI’s parallelization. Contact us if you’d like to use this.
Code coverage is an area where our support is evolving. We’d love to have your feedback about how we could support it better. Let us know how you’re using it, how you’d like to use it, and what we could do better!