如何正确设置 SonarQube cfamil.gcov?

How Do I Setup SonarQube cfamil.gcov Correctly?

我无法在 SonarQube 中获取覆盖率报告。我有一个 C++ 项目,我正在为其使用 build-wrapper-linux-x86-64 和声纳扫描仪。源代码的基本静态分析似乎有效,但 SonarQube 中没有关于测试代码覆盖率的报告。

作为同一工作流程的一部分,我正在使用 lcov 和 genhtml 制作单元测试覆盖率报告,因此我相信大多数代码覆盖率步骤都得到了正确执行。当我手动查看 .gcov 文件时,我可以在第一列中看到 运行 计数,因此那里有数据。

我将我的代码组织成模块。 sonar-project.properties 文件包括以下内容:

# List of the module identifiers
sonar.modules=Module1,Module2

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=./Sources,./Tests
HeliosEmulator.sonar.sources=./Application,./Sources,./Tests
sonar.cfamily.build-wrapper-output=build_output

# Existing reports
sonar.cfamily.build-wrapper-output=build_output
#sonar.cfamily.cppunit.reportsPath=junit
sonar.cfamily.gcov.reportsPath=.
#sonar.cxx.cppcheck.reportPath=cppcheck-result-1.xml
#sonar.cxx.xunit.reportPath=cpputest_*.xml
sonar.junit.reportPaths=junit

我也想在 Sonar 工具下显示单元测试结果。由于我使用的是 CppUTest 框架,因此我目前没有 xunit 或 junit 测试输出。这可以作为一个单独的问题来处理,但由于我无法找到很多关于如何在线使用 cfamily 扫描仪的文档,我不知道未列出的测试是否相关。

我忘记正确设置我的 CI 系统。 运行 声纳扫描仪的作业不存在 .gcov 文件。它们仅存在于生成覆盖率报告的测试作业中。扫描仪作业中没有文件意味着它无法生成覆盖率报告。

当我设置 GitLab CI 系统时,我用来将 .gcov 文件保留为人工制品,覆盖率报告突然开始工作。

.gcov 文件由测试作业生成,需要通过 artefact 存储传输到声纳扫描仪作业。这是因为 GitLab CI 不在相关作业之间共享工作区,您必须明确说明必须复制哪些文件。