0

I tried running code coverage to see how good my test cases is. Then I found out there are some lines that got ignored by LCOV, like line 6,7,10,13 below. Why does LCOV does not take these into account when lines like line 6 (class domain { ) clearly ran during the test.

   1             : #include "ros/ros.h"
   2             : #include "gtest/gtest.h"
   3             : 
   4             : 
   5             : 
   6             : class domath {
   7             :         public:
   8           1 :                 int multiply(int a, int b) {return a * b;}
   9             : 
  10             : };
  11             : 
  12           5 : TEST(TestSuite, multiply_test_case1){
  13             :         domath math1;
  14           1 :         int a = 3;
  15           1 :         int b = 4;
  16           1 :         int c = math1.multiply(a,b);
  17           1 :         EXPECT_EQ(c,12) << "value should be 12";
  18             : 
  19           1 : }
  20             : 
  21             : 
  22           1 : int main(int argc, char **argv){
  23             : 
  24           1 :         testing::InitGoogleTest(&argc , argv);
  25           1 :         return RUN_ALL_TESTS();
  26             : 
  27           3 : }
  28             : 
Weiyu He
  • 93
  • 7
  • 3
    there is no code to execute in this lines. Why are you surprised? It is more important that LCOV do not shows `0` for any line. – Marek R Jun 19 '19 at 15:35
  • The only line you can have doubts is line `13`. Note that your `domath` class has trivial constructor. There is noting to do in constructor so respective code is not generated. As a result there is nothing to measure in line `13` too. – Marek R Jun 19 '19 at 15:39
  • But then why is line 19 and 27 counts as a executed line? – Weiyu He Jun 19 '19 at 16:28
  • Function returns `return` or just `}` generate code. Unwinding the stack frame, doing the return to the caller etc. Note the coverage on lines 12 and 22 for function entry. – Richard Critten Jun 19 '19 at 19:49

0 Answers0