The coverage of C# source code is different from OpenCover

The coverage of C# source code of SonarQube is different from OpenCover.

SonarQube version : 6.7

There are constant files with similar contents in project to analyze.
Basically, they are not included in the SonarQube analysis coverage scope.
The analysis results of SonarQube and OpenCover differ only when referencing fields of other classes.

SonarQube : Recognize a constant file that references a field of another class as a coverage target file.
OpenCover : Recognize a constant file that references a field of another class as a not coverage target file.

The expected behavior is that like OpenCover, all constant files are not included in the SonarQube analysis coverage scope.

Could I have you tell me the reason about this unexpected behavior.
Below are examples of constant files.

1.constant_file1.cs (not included in the scope)

namespace XXX.Constant
{
public static class Common
{
public const int CONST_HTTP_CLIENT_TIME_OUT = 30;
public const int CONST_HTTP_CLIENT_RETRY_TIMES_MAX = 3;
}
}

2.constant_file2.cs (included in the scope)

namespace XXX.Constant
{
public static class LogLevelEnum
{
public const int CONST_LOGLEVEL_DEBUG =(int)Microsof.Extensions.Logging.LogLevel.Debug;
public const int CONST_LOGLEVEL_INFOMATION = (int)Microsof.Extensions.Logging.LogLevel.Infomation;
public const int CONST_LOGLEVEL_WARNING = (int)Microsof.Extensions.Logging.LogLevel.Warning;
public const int CONST_LOGLEVEL_ERROR = (int)Microsof.Extensions.Logging.LogLevel.Error;
}
}

Thanks for your help.

hi and welcome to this community forum!

please update your SonarQube version, as 6.7 is not supported anymore - get the latest and greatest from sonarqube.org/

In SonarCsharp 8.6.1 we’ve added support for importing branch coverage from OpenCover reports. SonarQube 8.3 has this update.

As we don’t support SonarQube 6.7, I won’t answer your question. Please update to a supported version. Ideally the latest one :slight_smile:

Thanks!