mardi 3 mai 2016

Integrate Google Test/Google Mock Framework with Repo for testing

I'm a new programmer on this sort of stuff involving Repos, Makefiles, building and testing.

I got hooked up on GoogleTest framework and I've gone through the build of the framework on my GNU/Linux platform.

This was the steps I took building Gtest on my own disks:

  1. Copied and paste the zip file on http://ift.tt/1DHXe9D (can't seem to get internet connection on my desktop sharing system) to my directory /mydisk
  2. Unzip and go to googletest-master/googletest/ directory, mkdir build directory and go into /googletest/build
  3. Run this command on shell cmake -DBUILD_SHARED_LIBS=ON -Dgtest_build_samples=ON -G"Unix Makefiles" ..
  4. Run make on shell

I even made a new folder named /Gtest alongside where /googletest-master folder is and copied the libgtest.so, libgtest_main.so and /include/ folder to it.

So my current layout is as follows:

+-- Gtest
       +--include
            +--gtest
                 +-- *.h
       +--lib
            +-- libgtest.so
            +-- libgtest_main.so

+-- googletest-master
       +-- CMakeLists.txt
       +-- README.md
       +-- googlemock
       +-- googletest

+-- Project
       +-- include
       +-- src
             +-- Makefile
             +-- project
                  +-- *.cpp

Okay, so I wasn't sure how to compile and run the test (for example sample1.cc and sample1_unittest.cc) using this framework. I've looked up stackoverflow, and one of the way was that:

  1. setenv LD_LIBRARY_PATH mydisk/Gtest/lib
  2. setenv GTEST_HOME mydisk/Gtest
  3. run g++ -I $GTEST_HOME/include -L $GTEST_HOME/lib -lgtest -lgtest_main -lpthread sample1.cc sample1_unittest.cc -o test inside the /googletest/samples/ folder
  4. run ./test and successfully outputs the result.

This is a gist of what I can make off right now. Am I doing it right? or is there a better way to run the test?

Is this any different than what the Makefile in the googletest/build is doing?

I've even looked up the Makefile in the mydisk/googletest-master/googletest/make/and make, and it outputs a sample1_unittest. The thing I can't get my head around is, how can I integrate this framework or using this Makefile with my own Project I got from my Repo.

The Project file contains a bunch of .cpp in the /src/project folder and includes a Makefile outside of that folder. In the /Project/include contains a bunch oh .h files where all the .cpp is using. Running this Makefile using make will build all this project successfully.

What I wanted to do was test one of the functions inside the project using this framework and right now, I'm having trouble on how to integrate googletest with my project.

Should I code and just add on to the existing Project's Makefile or do I have to create a whole new Makefile to integrate them?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire