首页 > 解决方案 > 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%

似乎我需要一个测试来涵盖其他情况,但我无法弄清楚那是什么。

标签: unit-testingsonarqube

解决方案


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


推荐阅读