0

First, I am well aware of the "hidden branch" problem caused by throws/exceptions. This is not that.

What I am observing is:

  1. My test framework (googletest) has testing macros (EXPECT_TRUE for example).
  2. I write passing tests using the macros
  3. Measuring branch coverage now asymptotes at 50% because I have not evaluated that test in both a passing and a failing condition...

Consider the following:

TEST (MyTests, ContrivedTest)
{
    EXPECT_TRUE(function_that_always_returns_true());
}

Now assuming that I have every line and every branch perfectly covered in function_that_always_returns_true(), this branch coverage report will asymptote at 50% (because gcov does not observe line 3 evaluating in a failing condition, intentionally)

The only idea that I've had around this issue is that I could exclude the evaluation macros with something like LCOV_EXCL_BR_LINE, but this feels both un-ergonomic and hacky.

TEST (MyTests, ContrivedTest)
{
    bool my_value = function_that_always_returns_true();
    EXPECT_TRUE(my_value); //LCOV_EXCL_BR_LINE
}

This cannot be a niche problem, and I have to believe that people successfully use googletest with lcov/gcov. What do people do to get around this limitation?

sam
  • 488
  • 8
  • 21
  • Per Wikipedia, "in computer science, test coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs". What you are truly interested in is the coverage for your code under test. There is little sense in figuring out the coverage of the tests themselves. It makes total sense to exclude tests from the coverage reports. – VladLosev Jun 21 '21 at 23:06
  • You should only build your code under test with gcov/lcov support. You should build your tests without gcov/lcov support. – rveerd Jun 22 '21 at 11:48

1 Answers1

0

After looking for far too long, I realized that all the testing calls I want to filter out are of the pattern EXPECT_*. So simply adding:

lcov_excl_br_line=LCOV_EXCL_BR_LINE|EXPECT_*

to my lcovrc solved my problem

sam
  • 488
  • 8
  • 21