Skip to main content

Configure code coverage

Learn how to use the CI/CD Manager API to enable JaCoCo code coverage for your builds.

All sample requests in this guide include the following path parameters:

Parameter nameDescription
tenantIdTenant ID.
starSystemIdID of the GCC project (star system) that includes the InsuranceSuite application for which you modify the CI/CD configuration.
applicationIdInsuranceSuite application which includes the build. For example:
- PC for PolicyCenter
- BC for BillingCenter
- CC for ClaimCenter
- CM for ContactManager

Get configuration

By default, the JaCoCo code coverage is inactive. To verify if it is already enabled for your build, send the following GET request:

curl -X 'GET' \
'{baseUrl}/api/v2/tenants/{tenantId}/starsystems/{starSystemId}/cicd-configs/{applicationId}/insurer-config' \
-H 'accept: application/json' \
-H 'Authorization: Bearer {access_token}'

Response contains a JSON object with the CI/CD configuration for the selected InsuranceSuite application. Check if the code coverage is enabled for your build and what packages it includes.

For Server Tests, this information might look like this:

Example response
...
{
"gunitServerTests": {
"enableCodeCoverage": false,
"minCodeCoverageLinesPercentage": null,
"suites": [...],
"verifySuitesPresenceEnabled": true
},
"jacocoExcludeClasspathRules": [],
"jacocoIgnoreBasePackages": [],
"jacocoIncludeClasspathRules": ["**/*"],
"jacocoScanBasePackages": ["tenantId"],
}
...

Enable code coverage

To enable JaCoCo code coverage for a build, send the following PATCH request:

curl -X 'PATCH' \
'{baseUrl}/api/v2/tenants/{tenantId}/starsystems/{starSystemId}/cicd-configs/{applicationId}/insurer-config' \
-H 'Accept: */*' \
-H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json-patch+json' \
-d '{body}'

Where {body} contains an updated configuration. Follow the JSON Patch format.

For example, to enable code coverage for Server Tests, use the following:

Request body
[
{
"op": "replace",
"path": "/gunitServerTests/enableCodeCoverage",
"value": true
}
]

For a successful request, you will receive the 200 status code.


Verify changes in TeamCity

Once you enable code coverage for a build, and then run the build, you can verify the changes that these actions introduced in TeamCity:

Build steps

There is one additional step: Download JaCoCo agent. The Run test suite step changes to Run test suite with coverage.

To view build steps, go to the Build Log tab:

Build steps of Server Tests with enabled code coverage

Build parameters

There are four additional build parameters:

  • jacoco_agent_path
  • jacoco_jars_path
  • jacoco_scan_base_packages
  • jacoco_version

To view build parameters, go to the Parameters tab:

Build parameters for Server Tests with enabled code coverage


Enable minimum code coverage for Server Tests

Setting minimum code coverage for builds is possible when code coverage is enabled.

To enable minimum code coverage for a build, send the following PATCH request:

curl -X 'PATCH' \
'{baseUrl}/api/v2/tenants/{tenantId}/starsystems/{starSystemId}/cicd-configs/{applicationId}/insurer-config' \
-H 'Accept: */*' \
-H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json-patch+json' \
-d '{body}'

Where {body} contains an updated configuration. Follow the JSON Patch format.

For example, to enable 80% code coverage for Server Tests, use the following request body:

Request body
[
{
"op": "replace",
"path": "/gunitServerTests/minCodeCoverageLinesPercentage",
"value": 80
}
]

For value, use the minimum percentage of code coverage required for a build to pass.

For a successful request, you will receive the 200 status code.


Verify changes in TeamCity

Once you enable minimum code coverage for a build you can verify the change that this action introduced in TeamCity:

  1. In TeamCity, select a build.
  2. Select View configuration settings.
  3. In Failure Conditions, view Additional Failure Conditions.

The Additional Failure Conditions field with minimum code coverage type added.


Modify base packages

By default, JaCoCo analyzes only the classfiles included in the packages whose names start with your tenant ID. For example, if your tenant ID is acme, the analyzed packages include: acme.packagea, acme.packageb, etc.

You can modify this behavior by specifying which packages to include or exclude from the analysis. To change the list of analyzed base packages, send the following PATCH request:

curl -X 'PATCH' \
'{baseUrl}/api/v2/tenants/{tenantId}/starsystems/{starSystemId}/cicd-configs/{applicationId}/insurer-config' \
-H 'Accept: */*' \
-H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json-patch+json' \
-d '{body}'

Where {body} contains an updated configuration. To include packages, update the jacocoScanBasePackages parameter. To exclude packages, update jacocoIgnoreBasePackages. Follow the JSON Patch format:

  • For value, use an array of base packages to include or exclude in the analysis.
  • For package names, use the standard package paths. Do not use wildcards.

For example, to scan only packages com.tenant and com.custom.base, use the following:

Request body
[
{
"op": "replace",
"path": "/jacocoScanBasePackages",
"value": ["com.tenant", "com.custom.base"]
}
]

Verify changes in TeamCity

By including and excluding base packages, you update the values of the jacoco_scan_base_packages and jacoco_ignore_base_packages build parameters.

To verify this change in TeamCity:

  1. Go to the modified build and select the ellipsis next to the Run button.
  2. Open the Parameters tab.

jacoco_scan_base_packages parameter with updated value


Modify path patterns

By default, JaCoCo analyzes all classfiles included in the scanned packages. You can modify this behavior by specifying which path patterns to include or exclude from the analysis.

To change the list of scanned paths, send the following PATCH request:

curl -X 'PATCH' \
'{baseUrl}/api/v2/tenants/{tenantId}/starsystems/{starSystemId}/cicd-configs/{applicationId}/insurer-config' \
-H 'Accept: */*' \
-H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json-patch+json' \
-d '{body}'

Where {body} contains an updated configuration. Follow the JSON Patch format:

  • To include path patterns, modify jacocoIncludeClasspathRules.
  • To exclude path patterns, modify jacocoExcludeClasspathRules.
  • For value, use an array of path patterns.

For example, to exclude all XML files from the analysis, use the following:

Request body
[
{
"op": "replace",
"path": "/jacocoExcludeClasspathRules",
"value": ["**/*.xml"]
}
]

Verify changes in TeamCity

By modifying path patterns, you update the value of the jacoco_classpath_rules build parameter.

To verify this change in TeamCity:

  1. Go to the modified build and select the ellipsis next to the Run button.
  2. Open the Parameters tab.

Updated parameter value in TeamCity


Expose code coverage report for Server Tests

By default, JaCoCo doesn't provide you with the exec files of the code coverage report.

Once enabled, code coverage reports are stored in TeamCity artifacts under the jacoco folder in the jacoco.exec file. The jacoco folder contains one jacoco.exec file for each test suite.

Exposing the report is possible when code coverage is enabled.

To expose code coverage report for a build, send the following PATCH request:

curl -X 'PATCH' \
'{baseUrl}/api/v2/tenants/{tenantId}/starsystems/{starSystemId}/cicd-configs/{applicationId}/insurer-config' \
-H 'Accept: */*' \
-H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json-patch+json' \
-d '{body}'

Where {body} contains an updated configuration. Follow the JSON Patch format.

To expose code coverage report for Server Tests, use the following request body:

Request body
[
{
"op": "replace",
"path": "/gunitServerTests/exposeCodeCoverageReports",
"value": true
}
]

For a successful request, you will receive the 200 status code.


Verify changes in TeamCity

By exposing code coverage reports, you update Artifact paths.

To verify this change in TeamCity:

  1. In TeamCity, select a build.
  2. Select View configuration settings.
  3. In General settings, view Artifact paths.

The modules/configuration/build/jacoco/**/* => jacoco/ path is added in Artifact paths.

The Artifact paths field with additional path.

When you expose code coverage reports, TeamCity generates the jacoco folder for each build. To view a report:

  1. In TeamCity, select a build.
  2. In the Artifacts tab, expand the jacoco folder.

Troubleshooting

JaCoCo does not generate reports

JaCoCo generates a report only if the packages specified in the jacoco_scan_base_packages build parameter contain any classes.

To check how many files were analyzed, verify the JaCoCo logs:

  1. In TeamCity, select a build.
  2. In the Artifacts tab, select Show hidden artifacts.
  3. Open the .teamcity/coverage_jacoco/jacoco.log file.

JaCoCo logs in TeamCity

At the end of the file, there is information about how many classfiles were processed and analyzed. For example:

total 485070 classfiles processed, 0 analyzed

If there are 0 analyzed classfiles, JaCoCo does not generate a report.

In such case, update the jacoco_scan_base_packages parameter to include packages which contain classfiles. For details, see Change base packages.