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%
似乎我需要进行测试才能涵盖其他情况,但我无法弄清楚那是什么。
经过更多研究,这不是Sonarqube问题。 post(及其解决方法)很可能解释了我的问题的根本原因。
相关帖子:LCOV/GCOV branch coverage with C++ producing branches all over the place