phagio
phagio

Reputation: 196

Class definition marked as not covered

I set up Codecov for a personal (open source) project in Qt. The project is still mostly a stub (barely a couple of classes, and I tried to achieve 100% coverage as of now. However, looking at the headers of these two classes in the Codecov report, one is seen as covered and the other is not, even if there are unit tests for both of them and they both pass.

Attribute coverage fails

Character coverage passes

I tested both of them in Catch2:

#include "../thirdparty/catch/catch.hpp"
#include "character/attributes/attribute.h"

#define TEST_ATTRIBUTE_NAME "test-attribute"
#define TEST_ATTRIBUTE_VALUE 1

TEST_CASE("Attributes")
{
  SECTION("should create new attribute correctly (name constructor)")
  {
    character::attribute sut(TEST_ATTRIBUTE_NAME);
    REQUIRE(QString(TEST_ATTRIBUTE_NAME) == QString(sut));
    REQUIRE(0 == int(sut));
  }

  SECTION("should create new attribute correctly (name and value constructor)")
  {
    character::attribute sut(TEST_ATTRIBUTE_NAME, TEST_ATTRIBUTE_VALUE);
    REQUIRE(QString(TEST_ATTRIBUTE_NAME) == QString(sut));
    REQUIRE(TEST_ATTRIBUTE_VALUE == int(sut));
  }
}

Following the DRY principle I won't paste the test code for character::character ;)

At first I was using a using character::attribute directive in the attributes test, so I removed it to see if the namespace was causing troubles. Also, I conformed the brackets model of attribute to match character, all to no avail.

This isn't a critical issue, but I'm curious as to what may be causing this behaviour and if / how it can be fixed. Also, I wonder if I should actually cut off the headers folder entirely from coverage checks, but I think it wouldn't be good practice.

Insights?

Edit Looking at the Codecov output on Travis, I found that there are three occurrences of attribute.h. The first one displays the following information:

File '.../attributes/attribute.h'
Lines executed:100.00% of 1
No branches
Calls executed:100.00% of 1
Creating '^#...#attributes#attribute.h.gcov'

While the other two occurrences display the following:

File '.../attributes/attribute.h'
Lines executed:0.00% of 1
No branches
Calls executed:0.00% of 1
Creating '^#...#attributes#attribute.h.gcov'

I suspect thus that the only instance that gets considered is the last one, which shows 0% executions as opposed to character.h which only appears once in the log.

Upvotes: 0

Views: 979

Answers (1)

Matthieu Brucher
Matthieu Brucher

Reputation: 22023

If you want a proper coverage report, you need to run your build in debug mode. Optimized build will have code that has been removed.

gcov/lcov can only do so much with these missing bits, and that's why you don't see the code tagged as covered even if it was indeed tested.

Upvotes: 1

Related Questions