Code Coverage
Track how much of your code is covered by tests
Code Coverage
Code coverage shows what percentage of your code is exercised by tests. Harness displays coverage metrics in the Coverage tab of your pipeline execution, helping you identify untested code paths.
What You'll See
Total Coverage
Percentage of all lines covered by tests
Patch Coverage
Percentage of changed lines covered (PRs only)
Per-File Breakdown
Coverage percentage for each source file
For pull requests, the diff view shows line-by-line coverage:
Green - Line is covered
Red - Line is not covered
Yellow - Partially covered (some branches)
Supported Formats
LCOV
.info, .lcov
Python, Node.js, JavaScript, C/C++
JaCoCo XML
.xml
Java, Kotlin, Scala
Go Coverage
.out
Go
Pipeline Examples
Analyze Coverage Locally
Before uploading, you can analyze coverage locally:
This outputs coverage statistics without uploading to Harness, useful for debugging or local development.
Quality Gates
Enforce minimum coverage thresholds to fail pipelines that don't meet your standards. Use hcli cov wait-until to block the pipeline until coverage meets the specified thresholds.
You can specify one or both thresholds as needed:
This command:
Waits for coverage data to be available
Checks thresholds (if specified):
--gt: total coverage percentage--patch-gt: patch coverage percentage (for PRs)
Fails the pipeline if any specified threshold is not met
Example output when the quality gate fails:
Quality Gate Parameters
--gt
No
Minimum total coverage percentage required
--patch-gt
No
Minimum patch coverage percentage required (for PRs)
--timeout
No
How long to wait for coverage data (e.g., 1m, 30s). Default: 30s
CLI Reference
cov upload
Upload coverage reports to Harness. Automatically detects CI environment and configuration.
--file
Yes
Path to coverage file (LCOV .info or Go .out). Can be specified multiple times
--base
No
Base branch for diff coverage tracking (e.g., main, origin/main)
--patch
No
Only include coverage for lines changed in the diff (requires --base)
--tags
No
Tags to apply to the uploaded coverage report (can be specified multiple times)
--verbose
No
Enable verbose output for debugging (true or false)
--log-level
No
Set log level: debug, info, warn, error (default: info)
cov analyze
--file
Yes
Path to coverage file
cov wait-until
Wait for coverage data and enforce quality gates. Automatically detects CI environment. Specify one or both thresholds as needed.
--gt
No
Minimum total coverage percentage (e.g., 70)
--patch-gt
No
Minimum patch coverage percentage (e.g., 80)
--timeout
No
Wait timeout (e.g., 1m, 30s). Default: 30s
Troubleshooting
Coverage shows 0%
Verify the coverage file path matches your tool's output
Patch coverage not showing
Ensure you're running on a pull request build
File not found
Confirm coverage file was generated before the upload step
Invalid format
Verify the file format matches supported types (LCOV, Go)
Incomplete or inaccurate coverage
Check if tests failed or exited early. Some test runs that terminate prematurely (test failures with --exitfirst, crashes, timeouts) may generate incomplete coverage data. Ensure all tests complete successfully before evaluating coverage metrics
Next Steps
Upload test results to see tests alongside coverage
View flaky tests to identify unreliable tests
Last updated
Was this helpful?