Generating Coverage Data
To use Qlty’s code coverage features, you first need to generate coverage reports from your test suite. This page provides instructions for common languages and frameworks.
Supported Languages and Formats
Language-specific Instructions
JavaScript / TypeScript
JavaScript / TypeScript with Jest
Jest has built-in coverage reporting capabilities using Istanbul under the hood.
By default, Jest will output coverage reports to the coverage
directory, including an LCOV report at coverage/lcov.info
.
React
If you’re using Create React App, Jest is already configured. Simply run:
Node.js with NYC (Istanbul)
NYC will generate an LCOV report at coverage/lcov.info
.
Python
Python with pytest
This will generate a coverage report in Cobertura XML format at coverage.xml
.
Python with coverage.py
This will also generate a coverage report in Cobertura XML format at coverage.xml
.
Ruby
Ruby with SimpleCov
Add SimpleCov to your Gemfile:
Configure SimpleCov at the top of your test helper file (e.g., test/test_helper.rb
or spec/spec_helper.rb
):
Run your tests normally:
SimpleCov will generate a coverage report at coverage/.resultset.json
.
Go
Go
Go has built-in coverage capabilities:
This will generate a Clover XML report which Qlty can understand.
Java / Kotlin
Java / Kotlin with Gradle and JaCoCo
Add JaCoCo to your Gradle build:
Run tests and generate a JaCoCo report:
This will generate an XML report at build/reports/jacoco/test/jacocoTestReport.xml
.
Java / Kotlin with Maven and JaCoCo
Add JaCoCo to your Maven pom.xml
:
Run tests and generate a JaCoCo report:
This will generate an XML report at target/site/jacoco/jacoco.xml
.
PHP
PHP with PHPUnit
Configure PHPUnit in your phpunit.xml
:
Run PHPUnit:
This will generate a Clover XML report at coverage.xml
.
Swift
Swift with Xcode and slather
First, ensure code coverage is enabled in your Xcode scheme.
Then install slather:
Create a .slather.yml
file:
Run your tests and then generate a coverage report:
This will generate a Cobertura XML report in the coverage
directory.
Path Fixing
For Qlty to accurately match a coverage report file to files in your Git repository, paths must align. The paths in your coverage report should be relative to your Git project’s root, but this isn’t always the case by default.
To resolve path mismatches, the qlty coverage publish
command supports these flags:
--add-prefix
: Adds a prefix to file paths in coverage payloads--strip-prefix
: Removes a prefix from absolute paths in coverage payloads
Example:
Custom Formats with the Qlty Format
In the unlikely event that your coverage tool does not export coverage data in a supported format, you can convert your coverage data to the qlty
format. The Qlty format is a simple JSON Lines format where each line represents the coverage for a single file:
For each line in the file, the hits
array contains:
-1
for irrelevant lines (comments, whitespace)0
for uncovered lines- Positive numbers for the number of times a line was covered
Because the Qlty CLI is Open Source, you also have the opportunity to contribute your formatter back to the community. See the parser directory for other examples.
If writing a formatter is not something you’re up for, or you need assistance, feel free to contact us.
Learn more about the Qlty format
Next Steps
Once you’ve generated a coverage report, you can:
- Upload it to Qlty
- Set up CI integration to automate uploads
- Merge multiple reports if you have parallel tests