{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1686,"path":"application-development/automated-test-framework-atf/atf-code-coverage.md","title":"ATF Code Coverage","bundle":null,"doc_type":null,"release":"australia","body":"\n# ATF Code Coverage\n\nMetadata code coverage tracks which lines of code in your custom scripts are executed during ATF test runs. It helps identify untested code, validate test quality, and assess deployment risk in ReleaseOps.\n\nMetadata code coverage is a testing and quality assurance feature that automatically collects and analyzes code coverage data when running ATF tests. It provides visibility into:\n\n-   Which lines of code in your scripts execute during test runs\n-   Code coverage percentages at the script level and deployment level\n-   Gaps in test coverage across your custom code\n-   Integration with test triage and test result analysis\n\n## Supported Code Scopes\n\nMetadata code coverage can track code execution in the following scopes:\n\n-   Server-side scripts: Business rules, script includes, workflow activities, and other server-side code written in Rhino JavaScript\n-   Client-side scripts: Client scripts, UI policies, and other client-side code executed in the browser\n-   Global scope code: Custom global scope scripts and libraries\n-   Application-scoped code: Code within specific application scopes can be filtered and analyzed separately\n\n## Key Concepts\n\nLine coverage tracks whether individual lines of code in a script were executed during a test run. Line-level granularity helps identify which specific code paths are exercised by your tests.\n\nCoverage aggregation combines coverage data from multiple test runs to show cumulative coverage at the test, test suite, script, and deployment levels.\n\nTraced records are captured during test execution with code coverage enabled. The system records which table records and metadata attributes are accessed by your scripts. This tracing data is linked to coverage records for detailed analysis.\n\nTest result integration captures code coverage metrics at the test, test suite, and test result levels, allowing you to correlate test outcomes with the code paths they exercise.\n\n## Use Cases\n\nTest quality assessment uses code coverage data to identify critical code paths that lack test coverage and prioritize writing additional tests for those areas.\n\nDeployment risk analysis reviews code coverage data before deploying custom code changes to verify the modified code is adequately tested. Low coverage on recently changed code indicates higher deployment risk.\n\nTest triage and troubleshooting uses code coverage data to support the Test Triage feature. This feature helps identify why tests fail by showing which code paths were exercised and which metadata was modified.\n\nDeployment request assessment in ReleaseOps automatically evaluates code coverage as part of the deployment request assessment process. By default, if custom code coverage is below 70%, the deployment request transitions to the Reconciling state and a test failure task is created.\n\n## Deployment Coverage Threshold\n\nMetadata code coverage integrates with ReleaseOps deployment assessment. By default, if custom code in a deployment request has less than 70% ATF test coverage, the following occurs:\n\n-   The deployment request transitions to the `Reconciling` state\n-   A test failure task is automatically created\n-   Deployment is blocked pending review and potential remediation\n\nYou can adjust the coverage threshold in the deployment request assessment playbook. See [Set Automated Test Framework \\(ATF\\) code coverage](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/application-development/releaseops/set-atf-code-coverage-threshold.md) for configuration details.\n\n## Limitations and Considerations\n\nWhen working with metadata code coverage, be aware of the following:\n\n-   Code coverage collection may impact test performance. The system includes thresholds to prevent excessive data accumulation.\n-   Code coverage can be disabled globally or at the script level if performance becomes a concern.\n-   Data truncation: Large API request payloads may be truncated when persisted. By default, fields are limited to 4,000 characters. When truncation occurs, a `was_truncated` flag is set to `true` in the API response, with details provided in the `truncation_message` field. You can adjust the default limit using the `glide.db.truncate_utf8` system property.\n-   Coverage data is subject to database field length constraints. Fields affected include test\\_suite\\_results, test\\_results, and metadata\\_info JSON arrays.\n-   Code coverage only includes code executed by the server-side Rhino engine or browser; static metadata, configurations, and non-executable records are not covered.\n-   When tracing is interrupted due to threshold constraints, an indicator is recorded on the test result to show that coverage data is incomplete.\n\n## Availability\n\nMetadata code coverage is available starting with the Australia release.\n\n## Programmatic Access\n\nYou can retrieve and analyze code coverage data programmatically using the ATF Code Coverage REST API. The API provides three main endpoints for computing code coverage:\n\n-   `POST /api/now/atf/code_coverage/all` — Aggregates coverage across all scripts covered by specified test suite or test runs\n-   `POST /api/now/atf/code_coverage/by_script_id` — Computes coverage for specific script records\n-   `POST /api/now/atf/code_coverage/by_line_number` — Computes coverage using filtered line numbers per metadata record\n\nEach endpoint returns coverage percentages at the script and deployment levels, along with metadata about the request and any data truncation warnings. For detailed API specifications, parameter documentation, and code examples, see [ATF Code Coverage API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/atf-code-coverage-api.md).\n\n## Related Features\n\n-   Automated Test Framework \\(ATF\\): The testing framework that generates code coverage data during test execution\n-   Test Triage: Analyzes test failures using code coverage and metadata tracing to identify root causes\n-   ReleaseOps: Integrates code coverage assessment into deployment request workflows\n-   Deployment Analyzer: Uses code coverage data to assess deployment readiness and risk\n\n**Parent Topic:**[Administering the Automated Test Framework \\(ATF\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/application-development/automated-test-framework-atf/atf-admin-overview.md)\n\n"}}