Qodana / Static Code Analysis Guide / What Is Code Coverage?

What Is Code Coverage?

Code coverage is a metric that shows how much of your source code is executed when your tests run and is one of Qodana’s top 6 metrics to empower your team. It helps developers understand which parts of an application are well tested, which areas are risky, and where additional tests are needed.

JetBrains tools including IntelliJ IDEA, Kotlin Multiplatform, and Qodana provide built-in coverage engines that help teams measure, visualize, and improve test coverage throughout the development workflow.

Why code coverage matters

Code coverage gives teams visibility into the relationship between their tests and the real behaviour of their systems.

When used correctly, it helps you uncover untested logic paths, avoid regressions by ensuring tests exercise critical code, reduce the chance of shipping unintended behaviour, prioritize risky areas of large and complex codebases and make test quality measurable - not just test quantity

A common misconception is that code coverage guarantees quality. It does not. Instead, it shows you where your tests aren’t looking yet.

How code coverage works

When you run test suites with coverage enabled, the coverage engine instruments your code and tracks which lines, branches, or instructions were executed during the test run.

Code coverage process: instrumentation, execution, report.

The basic workflow looks like this:

  1. Instrument code – JetBrains tools insert lightweight tracking instructions.
  2. Run tests – Your unit tests, integration tests, or UI tests execute.
  3. Capture execution data – The runtime records which parts of the program were reached.
  4. Produce a coverage report – You get highlighted source code and aggregated metrics.

JetBrains IDEs show this directly in the gutter, while Qodana produces coverage insights centrally as part of CI.

The types of coverage

Although “line coverage” is the most popular metric, JetBrains products support several levels of detail:

Line coverage

Shows which lines of code were executed during tests.
Useful for a quick overview of how thoroughly code is exercised.

Branch coverage

Shows whether both outcomes of conditional statements were tested.
This is important in languages like Java and Kotlin where complex logic often hides in conditions.

Instruction coverage

Looks at low-level bytecode execution.
JetBrains coverage engines use this for extremely precise reporting.

Method coverage

Indicates whether a method was entered at all during a test run.
This helps when you want to ensure API-level usage coverage.

The most common method for gauging code test coverage is to measure by the number of lines of code:

Code coverage percentage = (the number of lines of code tested by the algorithm / the total number of lines of code in a system component) * 100

However, there are two other strategies:

1) Measuring by statement
2) Measuring by branch, which is better connected to the cyclomatic complexity metric, as the complexity shows how many tests you need to implement to cover the code.

Code Coverage in JetBrains tools

In the IDE

IntelliJ IDEA and other JetBrains IDEs provide live visual feedback:

  • green lines are fully covered
  • yellow lines are partially covered
  • red lines were never executed
  • tool windows show percentages across files, modules, or the entire project

This immediate feedback helps developers adjust their tests while writing them.

In Qodana

Qodana integrates code coverage into continuous inspection:

  • collects coverage data during CI
  • aggregates results across branches and repositories
  • allows diff-based coverage to highlight how new changes affect overall quality
  • combines coverage with inspections, clone detection, and security checks

Coverage becomes part of the wider quality picture, not an isolated number.

You can also view code coverage in the Insights Dashboard which shows codebase health indicators projects.

How much Code Coverage do you need?

The right coverage target depends on your project’s goals and risk profile. Software developers seem to disagree widely about measurement value but we can provide some practical guidance:

Table of typical code coverage targets for different system types and their rationale.

The most reliable rule:
Aim for meaningful tests, not inflated numbers.

How Qodana uses Code Coverage data

Qodana enhances coverage by connecting it with static analysis:

  • highlights code that is uncovered and contains potential defects
  • identifies “dead zones” in the codebase
  • shows regressions in test coverage across pull requests
  • provides coverage-driven quality gates for CI
  • correlates low-coverage areas with high-risk inspections or security findings

This gives teams a smarter way to prioritise testing work and reduce technical debt.

List of best practices for using code coverage, including testing new code first and focusing on meaningful coverage.

A better way to understand test quality

Code coverage is a lens that helps developers understand their codebase, build safer systems, and confidently deliver changes at scale.

By combining JetBrains IDE coverage tools with Qodana’s continuous analysis, teams get:

  • consistent reporting across local and CI
  • early detection of risky, untested logic
  • centralized visibility for engineering managers
  • integrated insights across repositories
  • better quality code shipped with less manual effort

If you want test coverage to become an actionable part of your development workflow rather than an afterthought, Qodana brings it all together.