Leveraging Codecov Flags for Test‑Type Coverage Segmentation
Learn how Codecov coverage flags let you split uploads by test type—unit, integration, e2e—so you can see exactly where each suite contributes and target testing gaps.
29 Dec 2025, 17:31 UTC

The problem with a single coverage number
Many teams rely on Codecov’s overall percentage to judge test health. That single figure hides whether a line is exercised by unit tests, integration tests, or end‑to‑end tests. When a critical file shows 80 % coverage, you cannot tell if the missing 20 % is due to weak unit tests or a gap in your integration suite, making it hard to prioritize testing effort.
Thesis: coverage flags give you a granular view
Codecov’s coverage flags let you label each upload with metadata (e.g., unit, integration, e2e). The platform stores separate reports per flag and provides a dropdown to view coverage for each label. This reveals where each test suite contributes and where overlaps exist, without changing the underlying line‑hit data.
How coverage flags work
When you run the Codecov uploader you can pass the -F or --flags argument (or set flags: in codecov.yml) to attach one or more labels. The uploader sends the report together with the flag list; Codecov indexes the report under those flags. Later, in the project UI, you can select a flag to see only the coverage contributed by uploads that carried that label.
Flags are purely organizational: they do not alter the raw line‑hit data. If a line is hit by both a unit and an integration upload, it will appear as covered in both flagged views and also in the combined (all‑flags) view.
Worked example: Gradle Java project with unit and integration tests
Assume a Gradle build where test runs unit tests and integrationTest runs integration tests (using the JaCoCo plugin). JaCoCo produces two XML reports: build/reports/jacoco/test/jacocoTestReport.xml for unit tests and build/reports/jacoco/integrationTest/jacocoTestReport.xml for integration tests.
- Upload unit‑test coverage (run locally or in CI):
codecov -F unit -f build/reports/jacoco/test/jacocoTestReport.xmlThe command requires read access to the repository and a valid upload token (either via
CODECOV_TOKENenvironment variable or repository settings). If the uploader binary is not on$PATH, replacecodecovwith its full path. - Upload integration‑test coverage:
codecov -F integration -f build/reports/jacoco/integrationTest/jacocoTestReport.xmlSame permissions apply. In a CI pipeline you would typically invoke the uploader twice, once for each test suite, with different flags and report files.
- Verify the flagged views
After the uploads finish, open your project on Codecov.io. At the top of the coverage page you should see a dropdown labeled “Flags”. Selecting
unitshows coverage derived only from the first upload; selectingintegrationshows coverage from the second. The “All flags” option displays the combined view. - Check that no data is lost
Upload a third report without any flags (or with an empty flag list) and confirm that the reported total percentage matches the “All flags” percentage. This validates that the flagged uploads preserve the original line‑hit data.
Trade‑offs and limitations
- CI complexity: Each test suite requires a separate uploader invocation, adding steps to your pipeline. Forgetting a flag or using an inconsistent label will split coverage in unexpected ways.
- Overlapping coverage: Because flags do not deduplicate hits, a line covered by both unit and integration tests will be counted twice when you sum the flagged percentages. The combined view avoids double‑counting, but you must remember that the sum of individual flag percentages can exceed 100 %.
- Badge and threshold configuration: If you use Codecov’s status checks or badges, ensure they are set to evaluate the flag you care about (e.g., the
unitflag) or the combined view, otherwise you might enforce the wrong metric.
Getting started and practical verification
- Add a single flag to your existing unit‑test upload (e.g.,
-F unit). - Run the upload and check the UI: the flag dropdown should now list
unit. - Once confirmed, repeat the process for your integration test suite with a distinct flag (e.g.,
integration). - After both uploads succeed, use the flag dropdown to compare coverage per suite and identify gaps.
- Periodically run a flag‑less upload to verify that the combined coverage matches the sum of unique contributions (within the expected overlap tolerance).
By following these steps you turn a single opaque percentage into an actionable dashboard that tells you exactly where unit tests are strong, where integration tests add value, and where additional testing effort is needed.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.