Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk6 min

Java Code Coverage Tools: How to Measure Test Coverage

Use JaCoCo for repeatable Java coverage reports in Gradle or Maven, or inspect runs interactively in IntelliJ IDEA. Learn what line, instruction, and branch coverage reveal—and what percentages cannot prove.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For most Java projects, use JaCoCo to measure coverage in Maven or Gradle, then inspect the generated report for missed lines and decision outcomes. IntelliJ IDEA is useful for interactive local inspection. Run the tests with coverage instrumentation enabled before generating a report: coverage shows which code executed, not whether your tests would catch a defect.

Which Java coverage tool should you use?

Need Practical choice What to know
Repeatable report and CI checks in Gradle Gradle JaCoCo plugin Integrates with test tasks and supports configurable verification rules. The report task does not run tests automatically.
Maven test and report workflow JaCoCo Maven plugin Attaches a Java agent and generates reports. In the documented Surefire/Failsafe setup, tests must run in a fork; forkCount=0 or forkMode=never prevents collection.
Interactive local inspection IntelliJ IDEA coverage runner Displays coverage at project, class, method, and line levels; branch details depend on the runner and settings.
One report across Gradle subprojects Gradle JaCoCo report aggregation plugin Aggregates reports from multiple Gradle projects into an HTML report.

Choose based on build integration, the metrics you need, local inspection, multi-module reporting, and whether instrumentation works with your test execution setup. You can use build reports for repeatable CI results and an IDE runner for investigating code locally.

What coverage measures—and what it cannot tell you

Instructions, lines, and branches

JaCoCo measures execution of Java bytecode instructions. Line coverage maps execution to source lines when debug line information is available; a line is considered covered if at least one instruction assigned to it executes. Branch coverage counts outcomes associated with if and switch. Exception handling is not counted as branch coverage in JaCoCo’s counter model.

These metrics answer different questions. A test may execute a line containing a condition while exercising only one outcome. Branch data can reveal that gap. Method and class counters provide broader views, while complexity counters can help identify areas that may merit more tests. None of these measurements proves the assertions are meaningful or that a test would detect a fault.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use percentages as clues, not goals by themselves

There is no universal coverage threshold established by the tool documentation. A project can set its own minimum and fail a build when configured rules are violated, but a useful threshold depends on the code in scope, risk, legacy constraints, generated code, and the cost of tests that verify behavior. Prioritize uncovered boundaries, error handling, state changes, and consequential decisions rather than adding tests solely to change a report’s color.

Measure coverage in a Java project

  1. Choose the scope. Decide whether to include production code only, which modules count, and whether unit and integration test runs should be measured separately or together.
  2. Enable JaCoCo in the build. Apply the Gradle JaCoCo plugin for a Gradle workflow or configure the JaCoCo Maven plugin for Maven. For Gradle, use the Java plugin as appropriate for the project.
  3. Run the relevant tests with instrumentation active. Coverage data is produced while instrumented tests execute. In Maven’s documented Surefire/Failsafe setup, ensure tests run in a fork rather than disabling forking.
  4. Generate the report. In Gradle, run the test task and then jacocoTestReport. Its default HTML output is build/reports/jacoco/test/html. The report task does not automatically depend on or run tests. Maven examples place output under target/site/jacoco.
  5. Review missed behavior. Inspect uncovered lines and branches, then add tests where untested behavior matters. Consider boundary values, failure paths, state transitions, and the alternate outcomes of important decisions.
  6. Optionally enforce a project-specific rule. Configure Gradle’s JaCoCo verification task for a chosen scope and threshold if a build gate is useful. Account for generated code and legacy areas rather than imposing a number without context.
  7. Make CI outputs explicit. Keep test execution and report generation explicit in the pipeline. Preserve XML output if another system consumes it; use report aggregation when separate Gradle subprojects need a combined view.

Gradle workflow and common issues

Run tests before the report task

In a Gradle project with JaCoCo configured, a typical sequence is ./gradlew test jacocoTestReport. The first task executes tests and creates coverage data; the second renders the report. Running only jacocoTestReport does not guarantee fresh test data because that task does not run tests first.

Configure a verification threshold only when it reflects your policy

Gradle’s JaCoCo verification task supports rules that can make a build fail when a configured limit is missed. Set the rule for an appropriate code scope and metric. Treat it as an agreed project policy, not an industry-mandated percentage.

Combine reports for a multi-project build

For separate Gradle subprojects that need a single HTML view, use the JaCoCo report aggregation plugin. Aggregation does not remove the need to run the relevant tests and produce their coverage data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Maven workflow and common issues

Ensure the test process can load the JaCoCo agent

The Maven plugin attaches an agent to the test run. In the documented Surefire/Failsafe configuration, setting forkCount=0 or forkMode=never prevents coverage collection. If a report has no execution data, first confirm that the expected tests actually ran under the instrumented, forked test process.

Keep debug line information for source mapping

JaCoCo needs debug information to map execution back to source lines. Without it, instruction data may still be useful, but line-level mapping will be unavailable or incomplete.

Generate and locate the report

Configure the JaCoCo Maven plugin to create the report after the relevant test phase. Maven examples use target/site/jacoco for report output; confirm the configured location in your project when plugin settings differ.

Inspect coverage in IntelliJ IDEA

For a local run, use IntelliJ IDEA’s coverage action to run the relevant tests with a coverage runner, then inspect highlighted source and the coverage results. The IDE can show project, class, method, line, and branch information, depending on runner and options. Branch coverage is available with JaCoCo or with the IDEA runner when branch coverage is enabled. A partially exercised condition can therefore be visible even when its source line executed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting missing or misleading results

  • No execution-data file or an empty report: Confirm tests ran in the expected task and with the JaCoCo agent enabled. In Maven, check that the configured Surefire/Failsafe process forks. In Gradle, run tests before the report task.
  • HTML report exists but has no current test data: Regenerate coverage data by running the tests, then regenerate the report; report generation alone does not execute Gradle tests.
  • Lines are missing or line coverage looks incomplete: Check whether the compiled classes include debug line information, which JaCoCo needs for source-line mapping.
  • Line coverage looks high but a condition remains untested: Review branch coverage and exercise the alternative outcomes of important if and switch decisions.
  • Maven coverage disappears after changing test configuration: Check whether forkCount=0 or forkMode=never disabled the fork required by the documented Surefire/Failsafe setup.
  • A build fails after adding a coverage rule: Inspect which configured metric and code scope violated the threshold. Adjust the tests or policy deliberately; do not assume the threshold is universally correct.

Performance, reliability, and cost considerations

Coverage instrumentation is part of test execution, so include the coverage-enabled test run in CI time and make the required tasks explicit. For reliable comparisons, keep the measured scope and test sets consistent between runs; changing modules or combining unit and integration results changes what the percentage represents. The tool documentation reviewed here does not establish a general runtime overhead figure, so measure the impact in your own build rather than relying on an assumed percentage.

JaCoCo and the IDE runner support different inspection paths, but results depend on the actual test process, instrumentation, debug information, and selected metrics. Preserve machine-readable XML where downstream CI reporting needs it, and use aggregation when multiple Gradle projects must contribute to one report.

Or skip the browser setup

If you need a screenshot of a deployed, browser-accessible coverage report, you can capture a page through ScreenshotNeo. It is not a Java coverage tool and does not replace running instrumented tests or generating JaCoCo data. Its screenshot API accepts one GET request for an image or PDF; the example below saves a screenshot of a public page. See the ScreenshotNeo API documentation for parameters and output options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo’s free plan.

Further reading

Effective Software Testing by Maurício Aniche is an optional broader resource with Java-based examples and coverage-related testing material.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.