JaCoCo will output a binary file when run. This file does not contain all the information needed by Teamscale to process the coverage. You first need to convert it to JaCoCo's XML format, e.g. with the corresponding ANT task or Maven Pendant.


Upload via Python Client (recommended)

In order to upload coverage results to Teamscale, you need to have a server on which the following criteria are met:

  • Coverage result files (XML format) are available
  • Access to the running Teamscale server is possible
  • Python must be installed
  • Python pip must be able to download packages

As a first step, create a new user which will be able to upload coverage results to Teamscale. You can either use your administration account for this, or better use a special user in a group with the "Build" role. 


Install the Teamscale Python client. It contains a short example of how to upload Unit Test Coverage.

Be sure to change the coverage format in the Example to JACOCO before uploading JaCoCo coverage reports.

Please also use the Access Token, not the password of the user.


Upload via REST API (recommended)

In order to upload coverage results to Teamscale, you need to have a server on which the following criteria are met:

  • Coverage result files (XML format) are available
  • Access to the running Teamscale server is possible

As a first step, create a new user which will be able to upload coverage results to Teamscale. You can either use your administration account for this, or better use a special user in a group with the "Build" role. 


To upload one or more XML coverage files to Teamscale, issue the following HTTP request:


  • HTTP method: POST
  • URL: http://<YOUR_TEAMSCALE_SERVER>:<PORT>/p/<TEAMSCALE_PROJECT_ID>/external-report?format=JACOCO&partition=<PARTITION>&message=<MESSAGE>
    • YOUR_TEAMSCALE_SERVER:PORT is the address and port of the Teamscale instance
    • TEAMSCALE_PROJECT_ID is the ID of the Teamscale project into which to store the coverage
    • PARTITION is a logical name for the type of coverage. All coverage with the same partition will be grouped together. This, e.g. allows you to upload both coverage for your Java and your JavaScript tests without the results of one overriding those of the other. The name is descriptive and can be any arbitrary string.
    • MESSAGE is the message shown in the Activity perspective to the user. It should make clear that coverage was uploaded.
  • Content-type: application/x-www-form-urlencoded
  • Body: Form data. May contain any number of elements with name "report" and the content of a single coverage XML file.
  • Authentication: HTTP Basic Authentication with the build or admin user and their Access Token


Example curl invocation: 


curl -X POST -ubuild:arka9a78l0araklra87 -Freport=@coverage.xml "http://teamscale-server:8080/p/myProject/external-report?format=JACOCO&partition=Unit%20Tests&message=Unit%20Test%20Coverage"


Note that the uploaded coverage will be used for the current HEAD commit in Teamscale on the main branch. Should this not be the behaviour you want, you can override this by adding the following to the request's URL:

&t=<BRANCHNAME>:<TIMESTAMP>


This will cause Teamscale to store the coverage for the code on given branch at the given Java Unix timestamp (Epoch time in milliseconds).


Upload with ConQAT (deprecated)

In order to upload coverage results to Teamscale, you need to have a server on which the following criteria are met:

  • Teamscale distribution is available
  • Coverage result files (XML format) are available
  • The source code on which the coverage was calculated is available
  • Access to the running Teamscale server is possible

As a first step, create a new user which will be able to upload coverage results to Teamscale. You can either use your administration account for this, or better, use a special user in a group with the "Build" role. 

Now create a coverageupload.cqr file with the following content:

   

 

#!eu.cqse.conqat.engine.dashboard.teamscale.JaCoCoCoverageUploader
project.name=<TEAMSCALE PROJECT ID>
report-dir.dir=<PATH TO DIRECTORY CONTAINING JACOCO XMLs>
code-include.pattern=**.java
code-input.dir=<PATH TO SOURCECODE>
server.username=<TEAMSCALE USERNAME>
server.password=<TEAMSCALE-API-KEY>
server.url=<URL TO TEAMSCALE>
report-include.pattern=**.xml

 

   

Now make sure to fill in all the placeholders.


Finally run the configuration. You'll find the executables conqat.sh/.bat in the bin/ folder of your Teamscale distribution. Run it with:

 

./conqat.sh -f coverageupload.cqr

 



Special Cases:

How can I upload one report per folder into one teamscale project?


You can use the additional parameter:

 

analysis-identifier.value=project1

 

And use a unique identifier for each report you want to upload. This ensures that the reports will not overwrite each other.


How can I specify some of the properties from the cqr file using the command line?


Use the -p parameter like so:

./conqat.sh -f coverageupload.cqr -p code-input.dir=/home/code -p server.url=http://teamscale:1234

   

Test Gap analysis

How do I specify the source code revision that was tested?


Use the following additional parameter:

 

import-revision.value=1234567

 

How do I specify the coverage source?


Use the following additional parameter: 

 

analysis-identifier.value=Unit-Test

 

Caveats