samedi 18 septembre 2021

google test code coverage is not captured

I have written main.cc which call unit test code available in libAmazonplugin.so . Problem is code coverage is only captured for main.cpp but not for the actual definition inside libAmazonplugin.so

This is main.cpp files which call unit test available in libAmazonplugin.so

main.cpp **// code coverage is captured**

#include<stdio.h>
#include<iostream>

int main(int argc, char *argv[])
{
             
  int ret = run_test(argc,argv); // call to libAmazonplugin.so
}

Here is definition of run_test inside libAmazonplugin.so . Problem: why amazonclient.h code coverage is not captured

#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <stddef.h>
#include <stdio.h>

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "amazonclient.h" // code coverage is not capture why??

AmazonClient*obj = nullptr;

class AmazonPlugin: public ::testing::Test {
public:

  void SetUp( ) {
  
      if(obj== nullptr){
               
        obj = new AmazonClient();
          }
      
   }

   void TearDown( ) {
      if(obj!=nullptr){
        
          }
        }
};

TEST_F(AmazonPlugin, isRunning)
{
        if(obj!=nullptr){
                 EXPECT_EQ(false, obj->isRunning());
        }
        else{
              //no obj
        }
}

 int run_test(int argc, char *argv[])
{ 
        ::testing::InitGoogleTest(&argc, argv);
         return RUN_ALL_TESTS();
}

compiled command

 g++ main.cpp -I/usr/lib/  -std=c++11 -g -O0 -pthread -lgtest -lpthread -fprofile-arcs -ftest-coverage -lAmazonplugin 

Aucun commentaire:

Enregistrer un commentaire