Skip to main content
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 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 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 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 has built-in coverage capabilities:
This will generate a Clover XML report which Qlty can understand.

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 with PHPUnit

Configure PHPUnit in your phpunit.xml:
Run PHPUnit:
This will generate a Clover XML report at coverage.xml.

Swift Options

While there are multiple extraction options for Swift coverage data, each involves the same initial setup step: enable code coverage generation on your Xcode project or build. This can be done in your Xcode scheme, or via the xcodebuild command line option enableCodeCoverage YES.By providing these settings, Xcode will generate coverage data into a binary format. Coverage data next needs to be exported into a format recognized by Qlty.If you’re using Xcode 9.3 or later (recommended for most modern projects), we recommend using xccov to export coverage data, but you can also use Slather.If using an older version of Xcode, Slather is likely your best option.

Using xccov (Xcode >= 9.3)

xccov was introduced in Xcode 9.3 as a simplified way to extract coverage data. xccov enables extracting coverage data from a single consolidated .xcresult bundle, greatly simplifying coverage setup. To use xccov:
  1. Find / specify the location of the *.xcresult bundle If you are writing an Xcode build command yourself, you can supply it with the location where you’d like it to write the *.xcresult:
    If instead you are utilizing a CI provider’s Xcode test step which then executes Xcode on your behalf, examine the underlying xcodebuild command it uses. It may provide a standardized location for the .xcresult bundle. If not, the step may export an environment variable containing the path to the .xcresult bundle.
  2. Export coverage data using xccov
Qlty supports the xccov format which is output when passed --archive and --json are passed as arguments as follows:
xccov supports two (poorly documented) coverage export JSON schemas generated with the command line arguments --archive and --report. The --archive format is the only supported format, as it’s the only format that contains information about which specific lines were executed and which were not. Below are examples of the two formats for reference.
  1. When uploading this coverage data to Qlty, specify the format of the file as “xccov-json”
For example, for the GitHub coverage action you would specify:

Swift with Xcode and Slather (see Slather’s documentation for supported Xcode versions)

Slather is a Ruby gem that extracts coverage data from Xcode projects.On the pro side, Slather supports a wide range of Xcode versions, supports excluding files from coverage, and is fairly easy to use.On the con side, Slather relies on lower level Apple tools like llvm-cov which is more complex and relies on being able to locate coverage-related files. On simple projects this may be fine. More complex multi-module projects need extra setup to ensure all coverage data is extracted. See Slather’s documentation for more information. In general the setup process is as follows:
  1. Install Slather
  2. Create a .slather.yml file:
  3. Run your tests and then generate a coverage report:
    This will generate a Cobertura XML report in the coverage directory.
  4. When uploading coverage, specify the Cobertura format and provide the file generated by slather

Elixir with lcov_ex

Add lcov_ex to your dependencies in mix.exs:
Install the dependency:

Option 1: Using the mix lcov task

Run the lcov task to run tests and generate coverage:
This will generate a coverage report at cover/lcov.info.To output to a different folder:
This will generate the report at coverage/lcov.info.

Option 2: Using mix test —cover

Alternatively, configure LcovEx as your test coverage tool in mix.exs:
Then run tests with coverage:
This will generate a coverage report at coverage/lcov.info.

Umbrella Projects

For umbrella projects, running mix lcov at the umbrella level will generate coverage reports for all individual apps and compile them into a single file at cover/lcov.info.To keep the individual app coverage files as well:

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. Learn more about the Qlty format

Next Steps

Once you’ve generated a coverage report, you can: