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

LanguageFormat / Coverage Tool
RubySimplecov
JavaScriptLcov (generated by Istanbul)
PHPClover
GoClover
JavaCobertura and Jacoco
SwiftCobertura (using native Xcode coverage and slather)
KotlinCobertura and Jacoco
QltyThis is Qlty’s generic coverage format

Language-specific Instructions

JavaScript / TypeScript with Jest

Jest has built-in coverage reporting capabilities using Istanbul under the hood.

$# Add to your package.json or run directly
>"scripts": {
> "test": "jest --coverage"
>}

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:

$npm test -- --coverage

Node.js with NYC (Istanbul)

$# Install NYC
>npm install --save-dev nyc
>
># Add to your package.json
>"scripts": {
> "test": "nyc mocha"
>}

NYC will generate an LCOV report at coverage/lcov.info.

Python with pytest

$# Install pytest-cov
>pip install pytest-cov
>
># Run tests with coverage
>pytest --cov=. --cov-report=xml

This will generate a coverage report in Cobertura XML format at coverage.xml.

Python with coverage.py

$# Install coverage.py
>pip install coverage
>
># Run your tests with coverage
>coverage run -m pytest
>
># Generate an XML report
>coverage xml

This will also generate a coverage report in Cobertura XML format at coverage.xml.

Ruby with SimpleCov

Add SimpleCov to your Gemfile:

1group :test do
2 gem 'simplecov', require: false
3end

Configure SimpleCov at the top of your test helper file (e.g., test/test_helper.rb or spec/spec_helper.rb):

1require 'simplecov'
2SimpleCov.start
3
4# Rest of your test helper file...

Run your tests normally:

$bundle exec rspec
># or
>bundle exec rails test

SimpleCov will generate a coverage report at coverage/.resultset.json.

Go

Go has built-in coverage capabilities:

$# Run tests with coverage
>go test -coverprofile=coverage.out ./...
>
># Convert to Clover format for Qlty using goclover
># First install goclover: go install github.com/t-yuki/goclover@latest
>goclover coverage.out > clover.xml

This will generate a Clover XML report which Qlty can understand.

Java / Kotlin with Gradle and JaCoCo

Add JaCoCo to your Gradle build:

1plugins {
2 id 'jacoco'
3}
4
5jacoco {
6 toolVersion = "0.8.8"
7}
8
9jacocoTestReport {
10 reports {
11 xml.required = true
12 csv.required = false
13 html.required = true
14 }
15}

Run tests and generate a JaCoCo report:

$./gradlew test jacocoTestReport

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:

1<plugin>
2 <groupId>org.jacoco</groupId>
3 <artifactId>jacoco-maven-plugin</artifactId>
4 <version>0.8.8</version>
5 <executions>
6 <execution>
7 <goals>
8 <goal>prepare-agent</goal>
9 </goals>
10 </execution>
11 <execution>
12 <id>report</id>
13 <phase>test</phase>
14 <goals>
15 <goal>report</goal>
16 </goals>
17 </execution>
18 </executions>
19</plugin>

Run tests and generate a JaCoCo report:

$mvn clean test

This will generate an XML report at target/site/jacoco/jacoco.xml.

PHP with PHPUnit

Configure PHPUnit in your phpunit.xml:

1<phpunit>
2 <!-- ... other configuration ... -->
3 <coverage>
4 <report>
5 <clover outputFile="coverage.xml"/>
6 </report>
7 </coverage>
8</phpunit>

Run PHPUnit:

$phpunit --coverage-clover=coverage.xml

This will generate a Clover XML report at coverage.xml.

Swift with Xcode and slather

First, ensure code coverage is enabled in your Xcode scheme.

Then install slather:

$gem install slather

Create a .slather.yml file:

1coverage_service: cobertura_xml
2xcodeproj: YourProject.xcodeproj
3scheme: YourScheme
4output_directory: coverage

Run your tests and then generate a coverage report:

$xcodebuild -project YourProject.xcodeproj -scheme YourScheme -derivedDataPath Build/ -enableCodeCoverage YES test
>slather

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:

$# If your coverage report has absolute paths like /home/user/project/src/file.js
># but should be relative like src/file.js
>qlty coverage publish --strip-prefix=/home/user/project coverage.xml

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:

1{ "path": "src/user.js", "hits": ["-1", "-1", "0", "0", "1", "4", "1", "2", "0", "-1"] }

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: