Question Dilemma over authenticity of gcov generated code coverage percentage where unit tests are not technically correct

harshilshah25

Junior Member
Jun 27, 2021
1
0
6
When I joined my company as a new comer and I was exploring the unit test suite of the product code. It is using gtest framework. But when I checked all the tests, they were testing the whole functionality by calling real functions and asserting expected output. Below is one such test case as an example:

C++:
TEST(nle_26, UriExt1)
{
    int threadid = 1;
    std::shared_ptr<LSEng> e = std::make_shared<aseng:: LSEng >(threadid, "./daemon.conf");
    std::shared_ptr<LSAttrib> attr = e->initDefaultLSAttrib();
    e->setLSAttrib( attr );
    std::shared_ptr<DBOwner> ndb = e->initDatabase(datafile,e->getLogger());
    e->loadASData(ndb);
    e->setVerbose();
    std::shared_ptr<NewMessage> m = std::make_shared<NewMessage>(e->getLogger());
    ASSERT_TRUE(m != nullptr);
    ASSERT_TRUE(e != nullptr);
    m->readFromFile("../../msgs/nle1-26-s1");
    e->scanMsg(m, &scan_callBack_26, NULL);
    std::map<std::string, std::vector<std::string>> Parts = e->verboseInfo.eventParts;
    std::vector<std::string> uris = Parts["prt.uri"];
    ASSERT_EQ(uris.size(), 2 );
    ASSERT_EQ(uris[0] , "mailto:www.us_megalotoliveclaim@hotmail.com");
    ASSERT_EQ(uris[1] , "hotmail.com");
}

I found all the tests in the unit test directory having the same pattern like:
- Creating and initialising actual object
- Calling actual function
- Starting actual daemon
- Loading actual database of size around 45MB
- Sending actual mail for parsing to daemon by calling actual scanMsg function, etc.

So, all the tests appear more of as functional or integration tests, rather than unit tests, which ideally should be testing about a particular unit or function code.

But, the critical part is, on their official intranet site, they have projected the code coverage percentage of this product as 73%, computed using gcov.

Now, code profiling tools like gcov computes coverage on the following params:
1. How often each line of code executes
2. What lines of code are actually executed
3. How much computing time each section of code uses.

As, these tests are running actual daemon, loading real database and calling actual functions to scan the message including actual network (socket) calls. Of course, above 3 params will play some role in it, so I doubt the code coverage number will be completely zero, but in my opinion, it is not authentic.

As per my understanding, term code coverage is generally used with white box testing, as they are written by developers.

So my bothering questions are:
  1. In blackbox, testers unaware of the inside code, writes test cases to test the functionalities specific to requirements. Black box testing also does functional testing just as this, so what's the difference between above kind of test and functional test, I mean as they are definitely not standard UT.
  2. Apparently, test suite consists of all technically incorrect unit tests by its standard definition. Purpose of unit test is to test the code itself, by smallest unit wise. So does gcov generated coverage on such test suite, can be considered trusted and authentic? [I honestly don't think so.]
This is haunting me for some time. So thought to serve on the table for experts.
Thanks in advance.