Code Coverage with TCT

In order to obtain the code coverage of your unit tests, you can use the Test Coverage Tool that can be found on InterSystems Open Exchange.

1. Setup your environment

1.1 Download the Test Coverage Tool from Intersystems Open Exchange

1.2 Follow instructions from previous link to write and run your unit tests

1.3 Be sure to follow section "Reporting on results in Cobertura format", as you need to generate the Cobertura file

2. Define source and test paths

Option 1. Define the path of source files and test files in properties file


Option 2. Use parametrization on command line execution

sonar-scanner {...} -Dsonar.sources=./src -Dsonar.tests=./test

Option 3. Define test packages on your ZPM file

<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
  <Document name="config-api.ZPM">
      <Resource Name="Api.Config.PKG"/>
      <UnitTest Name="/tests" Package="UnitTests.Api.Config" Phase="test"/>

3. Add Code Coverage on Jenkins task

Option 1. Define the report paths in the properties file


Option 2. On the sonar-scanner execution, add the parameter -Dsonar.objectscript.cobertura.reportPaths:

cd "/opt/sonarqube/cachedb-import/output/$JOB_NAME"
/opt/sonarqube/sonar-scanner/bin/sonar-scanner \
      -Dsonar.projectKey="$JOB_NAME" \
      -Dsonar.projectName="$JOB_NAME" \
      -Dsonar.sources=./src \
      -Dsonar.tests=./test \
      -Dsonar.projectVersion=1.0 \
The sonar.objectscript.cobertura.reportPaths is a comma-separated list of paths