# How to Set Up Test Gap Analysis (TGA) with Mapping Files

In order to use the Test Gap analysis, you’ll need to upload test coverage to Teamscale.

Direct Upload

For most coverage profilers (e.g., JaCoCo), the resulting coverage files can simply be uploaded as described here.

For some profilers, however, Teamscale needs mapping files to interpret the coverage files.

Teamscale allows you to upload these mapping files ahead of time, e.g., when they are created during the build process. Then, when uploading coverage files, it will use the mapping files to interpret the coverage information. Since every time you build your application, new mapping files are generated, Teamscale needs to know, which mapping files to use when you upload coverage. Thus, during the upload of the mapping files, you must provide a version string (any unique string will do, e.g., a revision number). You must again provide the exact same version string when uploading coverage files that belong to those mapping files.

# Test Gap Analysis for JavaScript/TypeScript

To collect coverage in the browser, currently, only the Istanbul profiler's JSON format is supported by Teamscale. Since JavaScript may be minified and TypeScript is always transpiled to JavaScript before execution in the browser, you need to upload the mapping files (commonly called source map files in this context) generated during the build.

Please note that errors in the source maps can lead to subtle misalignment of the covered lines and thus to wrong coverage results. Please make absolutely sure that source maps are configured correctly for your entire build pipeline and that they correctly map back to your source files. Some minification/bundling tools are known to e.g., produce off-by-one source maps.

The following is an example of how to upload source map files using curl:

curl --request POST \
--user bob:e434mikm35d \
--form "file=@./source.map" \
localhost:8080/p/PROJECTID/javascript-source-map-upload?t=timestamp&version=version

The TIMESTAMP must be the java timestamp of the commit which was processed by the build to generate the mapping file.

The following is an example of how to upload Istanbul coverage files using curl:

curl --request POST \
--user bob:e434mikm35d \
--form "report=@./coverage.json" \
localhost:8080/api/projects/PROJECTID/external-analysis/istanbul-test-coverage?message=myMessage&partition=myPartition

# Test Gap analysis for JavaScript/TypeScript Data Flow

Test Gap analysis for JavaScript/TypeScript data flow

# Test Gap Analysis for C#

There are many C# profilers for which no special mapping files are needed. We do, however, have a custom low-overhead profiler. It is specially suited for the Test Gap analysis as it only records which methods were executed, not which particular lines. This allows it to have virtually no impact on performance. We have successfully used it to profile in several production environments.

Since only minimal information is recorded at runtime, Teamscale needs the PDB files generated during the build to interpret the coverage files.

The following is an example of how to upload PDB files using curl:

curl --request POST \
--user bob:e434mikm35d \
--form "file=@./assembly.pdb" \
localhost:8080/api/projects/PROJECTID/external-analysis/dotnet-debug-info?t=timestamp&version=myVersion

The TIMESTAMP must be the java timestamp of the commit which was processed by the build to generate the PDB file.

The following is an example of how to upload CQSE profiler coverage files using curl:

curl --request POST \
--user bob:e434mikm35d \
--form "report=@./coverage.txt" \
localhost:8080/api/projects/PROJECTID/external-analysis/dotnet-ephemeral-trace?version=myVersion&message=myMessage&partition=myPartition