---
url: /tutorial/generating-testwise-coverage.md
---

# Generating Testwise Coverage

To use the [Test Impact Analysis](../../introduction/test-selection/#test-impact-analysis), you'll need to provide per-test coverage in the [Testwise Coverage report](../../reference/upload-formats-and-samples/testwise-coverage/) format.
Unfortunately, most coverage tools do not provide coverage information on a per-test level, but rather for the full test run.

We offer plugins for certain languages and test runners, such as Java+JUnit 5 with Maven/Gradle, which can [collect Testwise Coverage](../../howto/providing-testwise-coverage/#java-virtual-machine-jvm).
It is recommended that you use these plugins if they are available for your language and test runner.
We are also working on extending the support for other languages and test runners.

If you use technologies for which we do not have plugins available, but are already able to gather coverage data at a per-test(-suite) level, you can use our [`teamscale-build` command-line tool](../../reference/cli/teamscale-build/).

This tutorial will teach you how to use `teamscale-build` to convert these reports into a single Testwise Coverage report.
This will allow you to use the [Test Impact Analysis](../../introduction/test-selection/#test-impact-analysis).

## 1. Download

Download the `teamscale-build` tool from [here](../../reference/cli/teamscale-build/#installation) and install it.

## 2. Place All Coverage Files Into a Directory

For this tutorial, we have prepared two sample coverage reports.
You can download them from here:


The ZIP file contains the following files:

```text
sample_reports/
├── expected_output.json
└── input_files/
    ├── AnotherTest/
    │   ├── metadata.json
    │   └── SIMPLE/
    │       └── report1.simple
    └── SomeTest/
        ├── metadata.json
        └── SIMPLE/
            └── report1.simple
```

The `expected_output.json` is a copy of the Testwise Coverage report that we are about to generate.
The `input_files` contain the coverage reports.
The reports are given in the [Teamscale Simple Coverage](../../reference/upload-formats-and-samples/#example-file-for-teamscale-simple-coverage) format, but most of the [Teamscale-supported coverage formats](../../reference/supported-technologies/test-coverage/#recommended-test-coverage-profilers) are also [supported by `teamscale-build`](../../reference/cli/teamscale-build/#input-coverage-format).
The format of the reports is encoded in the name of the folder containing the reports.

The `metadata.json` files contain metadata about each test such as its path, duration and result.
See [the `teamscale-build` documentation for all available attributes](../../reference/cli/teamscale-build/#input-path-structure).

:::warning Creating the folder structure
For your own tests, you are responsible for creating the correct folder structure and `metadata.json` files yourself.
:::

## 3. Convert the Reports

Execute the following command to convert all Simple coverage reports from the directory `input_files` to a single Testwise Coverage report and save this report to the file `testwise-report.json`.

:::: tabs key:os
\== Linux

```shell
teamscale-build coverage testwise -i ./input_files -o testwise-report.json
```

\== Windows

```batch
teamscale-build.bat coverage testwise -i .\input_files -o testwise-report.json
```

\== macOS

```shell
teamscale-build coverage testwise -i ./input_files -o testwise-report.json
```

::::

## 4. Uploading the Generated Testwise Coverage Report to Teamscale

Now, repeat the same process for your own tests to generate a testwise coverage report for your software system.

To view the result in Teamscale, use our [upload tool `teamscale-upload`](../../howto/uploading-external-data/#upload-via-command-line) to upload the generated `testwise-report.json` to your Teamscale instance.
Specify the format `TESTWISE_COVERAGE`.

You can view the results under *Metrics* > *Tests*.
