Clarify the difference between lines of code and lines to cover

I’m a little confused by the definition of (lines of code) and (lines to cover) on sonar documentation .
here is :
the lines of code : Number of physical lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment.
lines to cover : Number of lines of code which could be covered by unit tests (for example, blank lines or full comments lines are not considered as lines to cover).

I understand that lines of code = lines to cover WHEN covered lines =0
Can anyone explain more the difference if there is any, please?


Hey there.

Another way of saying “Lines to Cover” is “Executable Lines” or “Lines that can be covered by unit tests”

Consider a Java example:

package org.eclipse.jdt.core.dom;

import javax.annotation.Nullable;

Surely these are Lines of Code, but they can’t be covered by unit tests

While some logic like this can (and should) be covered by Unit Tests.

if (answer == null) {

The latter sample falls under “lines to cover” (well, the first two lines, not the closing bracket :grinning_face_with_smiling_eyes:), the former does not, but they are all “lines of code”