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:
“`
TEST(nle_26, UriExt1)
{
int threadid = 1;
std::shared_ptr
std::shared_ptr
e->setLSAttrib( attr );
std::shared_ptr
e->loadASData(ndb);
e->setVerbose();
std::shared_ptr
ASSERT_TRUE(m != nullptr);
ASSERT_TRUE(e != nullptr);
m->readFromFile(“../../msgs/nle1-26-s1”);
e->scanMsg(m, &scan_callBack_26, NULL);
std::map
std::vector
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.
So my bothering question is:
Apparently, test suite consists of all technically incorrect unit tests by its standard definition. So does gcov generated coverage on such test suite, can be trusted or reliable? [I honestly don’t think so.]