Import of reports of code coverage by Jacoco

Themis analyzes the reports produced by Jacoco solely at the XML format.

Preparation of the source in Themis

The reports of code coverage produced are tied to one of your code repository. You have to indicate to your Themis source that the data associated with the code coverage will come from external reports. 

To this end, seek in the Administration part, then Projects and identify the concerned Source. Add then two plugins respectively for the Code coverage practices and Test-First Development, by indicating Import of reports of code coverage for external files. As a reminder, the addition of a plugin forms in opening the listing of plugins of the source, then by clicking on Addition of a plugin.

There is no need here to specify that it is a Jacoco report, that will form on mailing files.

Mailing of reports with the Jenkins plugin

Pre-requisite: When your automated unit tests are performed in Themis, on or several Jacoco reports are produced.

In Jenkins, add a step in the Actions folllowing the build part, by clicking on the Add an action after the build drop-down. Select Send report files to Themis.

Select the body of Themis and indicate the key of the source linked with the source code repository ongoing analysis in Jenkins.

In the Report Files section, select for Type the Jacoco value. Then in Path, indicate one or several expressions (separated by commas) allowing to access to the XML files produced by Jacoco.

For example, if you use Maven + Jacoco, your project has probably the following architecture after execution of tests:

pom.xml
module1
------- pom.xml
------- target/site/jacoco/jacoco.xml
module2
------- pom.xml
------- target/site/jacoco/jacoco.xml

In this example, you have 2 Maven modules in your project. The expression to indicate will be the following: **/target/**/jacoco.xml

Mailing of reports via the REST API

If you do not use Jenkins, or do not wish to use the Jenkins plugin, it is possible to use the API of Themis to synchronize the Jacoco reports of coverage. Here is an example of BASH script that you may implement in an other language if you wish (the variables at first are to adapt in you context):

#!/bin/bash

#TOCHANGE THEMIS_URL="http://mythemis.com" SOURCE_KEY="da4e11f4-5489-4b2a-a028-20d071b1c671" API_KEY="NWJjZWQ3ZmNhYTJhYzkwMWRmNGZhYTYx" JACOCO_REPORT_FILE="jacoco.xml" CURRENT_COMMIT=$(git rev-parse HEAD) #Current GIT commit
#For SVN : $(svn info --show-item last-changed-revision) CURRENT_DATE=$(date +%s)"000" WORKSPACE=$(pwd) #the root directory of the source code repository REPORT_ARCHIVE="themis_report.zip" #First of all, create a directory with all Jacoco reports REPORT_DIR=$(mktemp -d -p /tmp) find . -name $JACOCO_REPORT_FILE -exec cp --parents \{\} $REPORT_DIR \; if [ -e $REPORT_ARCHIVE ];then echo "Remove existing archive" rm $REPORT_ARCHIVE else echo "File "$REPORT_ARCHIVE" does not exist" fi #Create archive to send to Themis zip -r $REPORT_ARCHIVE $REPORT_DIR curl -i \ -H "Content-Type: multipart/form-data" \ -H "Accept: application/json,application/zip" \ -H "themis-api-key:$API_KEY" \ -X POST \ -F 'metadata={ "executionDate" : "'$CURRENT_DATE'", "dataType" : "jacoco", "commit" : "'$CURRENT_COMMIT'", "dataWorkspace" : "'$WORKSPACE'"};type=application/json' \ -F "archive=@"$REPORT_ARCHIVE";type=application/zip" \ $THEMIS_URL/api/reportFiles/$SOURCE_KEY rm -rf $REPORT_DIR
rm $REPORT_ARCHIVE
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.