Import of reports of code coverage by Cobertura

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

Preparation of the source in Themis

The produced reports of code coverage are linked with 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 involved Source. Add then two plugins respectively for the Code coverage and Test-First Development practice, by indicating Import of reports of code coverage for external files. As a reminder, the addition of a takes place 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 Cobertura report, that will form on mailing files.

Mailing of reports with the Jenkins plugin

Pre-requisite: When your automate unit tests are performed in Themis, one or several Cobertura reports rapports are produced.

In Jenkins, add a step in the Actions following 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 ted to the code repository ongoing analysis in Jenkins.

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

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

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

In this example, you have 2 Maven modules in your project. The expression to indicate will be the following: **/target/**/cobertura.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 Cobertura 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 your context):

#!/bin/bash

#TOCHANGE THEMIS_URL="http://mythemis.com" SOURCE_KEY="da4e11f4-5489-4b2a-a028-20d071b1c671" API_KEY="NWJjZWQ3ZmNhYTJhYzkwMWRmNGZhYTYx" COBERTURA_REPORT_FILE="cobertura.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 an archive with all Cobertura reports REPORT_DIR=$(mktemp -d -p /tmp) find . -name $COBERTURA_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" : "cobertura", "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.