unit-testing - Sonarqube 部分覆盖的测试
问题描述
Sonarqube 测试覆盖率报告说我的 c++ 语句只被部分覆盖。包含此类语句的非常简化的函数示例如下:
std::string test(int num) {
return "abc";
}
我的测试如下:
TEST(TestFunc, Equal) {
std::string res = test(0);
EXPECT_EQ (res, "abc");
}
Sonarqube 覆盖率报告说,返回 stmt 仅被测试部分覆盖(2 个条件中的 1 个)。我想知道我需要测试的其他条件是什么?
我还在报告中看到了以下内容:
Condition to cover: 2
Uncovered Condition: 1
Condition Coverage: 50%
似乎我需要一个测试来涵盖其他情况,但我无法弄清楚那是什么。
解决方案
After more research, this is not a Sonarqube problem. This post (and the way around it) most likely explain the root cause of my problem.
Related post: LCOV/GCOV branch coverage with C++ producing branches all over the place
推荐阅读
- nginx - 用于从现有短链接 Web 服务创建短链接服务的 NGINX 配置
- android-fragments - 使用导航从工具栏菜单项单击在片段之间传递数据 - Kotlin
- android - 接收器在调用设备时忽略 screen_on 操作
- php - 语法错误,第 34 行 C:\xampp\htdocs\latihan\Prosesdaftar.php 中的意外 'else' (T_ELSE)
- android - GPS定位不起作用
- opengl - 是从三角形创建圆还是用片段着色器更快地绘制它们?
- ios - Firebase 无法连接到服务器
- node.js - 当我启动我的 node.js 服务器时,它启动但给出了一些错误
- c++ - 为什么允许从对象到引用的隐式转换?
- gitlab - 如何在同一台服务器上从 Gitlab 克隆?