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.
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
- 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.
- 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.
- 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.
- Generate the report. In Gradle, run the test task and then
jacocoTestReport. Its default HTML output isbuild/reports/jacoco/test/html. The report task does not automatically depend on or run tests. Maven examples place output undertarget/site/jacoco. - 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.
- 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.
- 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.
Rank #2
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.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
Rank #4
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.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Best Value
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
ifandswitchdecisions. - Maven coverage disappears after changing test configuration: Check whether
forkCount=0orforkMode=neverdisabled 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.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Sign 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.
Quick Recap
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.




