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 name | Description |
---|---|
tenantId | Tenant ID. |
starSystemId | ID of the GCC project (star system) that includes the InsuranceSuite application for which you modify the CI/CD configuration. |
applicationId | InsuranceSuite 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:
...
{
"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:
[
{
"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 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:
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:
[
{
"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:
- In TeamCity, select a build.
- Select View configuration settings.
- In Failure Conditions, view Additional Failure Conditions.
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:
[
{
"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:
- Go to the modified build and select the ellipsis next to the Run button.
- Open the Parameters tab.
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:
[
{
"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:
- Go to the modified build and select the ellipsis next to the Run button.
- Open the Parameters tab.
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:
[
{
"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:
- In TeamCity, select a build.
- Select View configuration settings.
- In General settings, view Artifact paths.
The modules/configuration/build/jacoco/**/* => jacoco/
path is added in Artifact paths.
When you expose code coverage reports, TeamCity generates the jacoco
folder for each build. To view a report:
- In TeamCity, select a build.
- 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:
- In TeamCity, select a build.
- In the Artifacts tab, select Show hidden artifacts.
- Open the
.teamcity/coverage_jacoco/jacoco.log
file.
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.
Was this page helpful?