Coveralls is a code coverage monitoring tool that tracks which lines of your source code are executed during automated tests. It integrates with your continuous integration (CI) system to receive coverage reports and visualize them in a dashboard, allowing you to see exactly where tests are missing.
To use Coveralls, you must first generate a coverage report in your local environment or CI pipeline using a language-specific tool. Coveralls does not run the tests itself; it acts as a storage and visualization layer for the data produced by those tests.
Connecting Your Repository to Coveralls
Integration begins by linking your version control system, such as GitHub or GitLab, to the Coveralls account. Once linked, you must select the specific repository you wish to monitor. This connection allows Coveralls to associate coverage reports with specific commits, branches, and pull requests.
After linking the repository, you will receive a unique repository token. This token is a string of characters used to authenticate your CI server when it uploads the coverage report. You must add this token as an environment variable or a secret in your CI settings, typically named COVERALLS_REPO_TOKEN. Using a secret ensures that your token is not exposed in plain text within your configuration files.
If you are using a public repository, some integrations allow for tokenless authentication through OAuth, but private repositories always require the token for security. Labels and menu paths for adding secrets may vary by CI provider, but are generally found under Settings > Secrets or Settings > CI/CD Variables.
Configuring Language-Specific Coverage Tools
Coveralls requires a report in a format it can understand. Because different programming languages use different testing frameworks, you must install a specific "client" or "reporter" for your language.
Python Configuration
Python projects typically use coverage.py to track execution. You must install the coveralls Python package. In your CI configuration file, you run your tests first, then execute the coveralls command to upload the .coverage file. If you are using pytest, the pytest-cov plugin is the standard way to generate the initial data before the upload step.
JavaScript and TypeScript Configuration
For Node.js projects, Istanbul or nyc is the standard tool for generating coverage data. You configure these tools to output a lcov.info file. The Coveralls JavaScript client then reads this LCOV file and sends it to the Coveralls API. You can specify the output directory in your package.json or a separate .nycrc configuration file.
Ruby Configuration
Ruby projects use the SimpleCov gem. You must add the coveralls` gem to your Gemfile and require it within your spec_helper.rb or test_helper.rb file. SimpleCov handles the tracking, and the Coveralls integration automatically formats the result for upload upon the completion of the test suite.
Monitoring Coverage Trends and Regressions
Monitoring is the process of observing how coverage changes over time. The Coveralls dashboard provides a percentage of the total codebase that is covered by tests. A drop in this percentage indicates that new code has been added without corresponding tests, or that existing tests have been removed.
You can set a "coverage drop" threshold. This is a configuration setting that determines how much the coverage percentage can decrease before a build is marked as failed. For example, if you set a threshold of 1%, a pull request that drops total coverage from 85% to 83% will trigger a failure notification. This prevents "coverage erosion," where the quality of the test suite slowly declines over months of development.
The dashboard also allows you to view coverage by file and by line. Lines highlighted in green are covered, while red lines have never been executed during a test run. This allows you to identify "dark" areas of the code—complex logic or edge cases that are completely untested—and write targeted tests to cover them.
Integrating Coverage into Pull Request Workflows
The most effective way to use Coveralls is by integrating it directly into the pull request (PR) process. When a developer pushes code to a branch, the CI system runs the tests and sends the report to Coveralls. Coveralls then posts a comment or a status check back to the PR.
This status check provides immediate feedback to the reviewer. If the PR increases coverage, it is seen as a positive contribution. If it decreases coverage significantly, the reviewer can request that the author add more tests before the code is merged into the main branch. This shifts the responsibility of testing to the start of the development cycle rather than treating it as a cleanup task at the end.
To configure this, ensure that the "Status Checks" or "Commit Status" option is enabled in your Coveralls repository settings. This ensures that the CI pipeline waits for the coverage report to be processed before marking the build as successful.
Handling False Positives and Uncovered Code
Not every line of code should be covered by a test. Some code is boilerplate, such as getters and setters, or contains "impossible" error paths that cannot be triggered in a test environment without complex mocking. Forcing 100% coverage often leads to low-quality tests that only check if the code runs, rather than checking if the logic is correct.
To handle this, you can use "coverage exclusions." Most language-specific tools allow you to mark specific lines or files to be ignored by the coverage monitor. In Python, you can add a comment like # pragma: no cover to a line to tell the monitor to skip it. In JavaScript, you can use /* istanbul ignore next */.
Excluding these lines ensures that your coverage percentage reflects the actual logic of the application. If you find yourself excluding large portions of a file, it is a sign that the file may be doing too many things and should be refactored into smaller, more testable components. Regularly reviewing your excluded lines prevents developers from using these markers to hide untested, complex logic.
Signs of a Healthy Coverage Monitor
- The coverage percentage remains stable or increases as the project grows.
- Pull requests are blocked when coverage drops below a predefined threshold.
- Developers use the line-by-line view to identify and fill gaps in edge-case testing.
- Exclusions are used sparingly and only for non-logic boilerplate code.
- The CI pipeline fails if the coverage report fails to upload.