3

Sonarqube test coverage report says that my c++ statement are only partially covered. Example of a very simplified function containing such statements is as below:

std::string test(int num) {
    return "abc";
}

My test as follow:

TEST(TestFunc, Equal) {
    std::string res = test(0);
    EXPECT_EQ (res, "abc");
}

Sonarqube coverage report says that the return stmt is only partially covered by tests (1 of 2 conditions). I am wondering what is other condition that i need to test for?

I also saw the following in the report:

Condition to cover: 2
Uncovered Condition: 1
Condition Coverage: 50%

It seems like i need a test to cover the other condition but i cant figure out what that is.

zeus1234
  • 453
  • 1
  • 5
  • 15

1 Answers1

1

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

zeus1234
  • 453
  • 1
  • 5
  • 15