Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure and setup google test framework in linux

I'm a newbie to g test and Here is what I am trying to do (On a Linux server from console): 1) Create a small project in C++ ( with a header file containing a function prototype, a cpp file with a function in it and another cpp file with main calling the function already defined in the header file ) 2) Configure g test to write unit tests and test the function created in the step 1 3) Create another small project with a couple of unit tests (different scenarios to test the function created under the project in step 1)

Can anyone please tell how to configure g test and the projects created with an example?

Thanks in advance

like image 439
Sidaze Avatar asked Nov 06 '13 11:11

Sidaze


People also ask

How do I setup a Google Test in Visual Studio?

Add a Google Test project in Visual Studio 2022 In Solution Explorer, right-click on the solution node and choose Add > New Project. Set Language to C++ and type test in the search box. From the results list, choose Google Test Project. Give the test project a name and choose OK.

Is Google Test a framework?

What is Googletest? It is a test framework i.e., a software tool for writing and running unit tests. It is a library for writing C++ tests. It is based on xUnit architecture which is a set of “Frameworks” for programming and automated execution of test cases.


1 Answers

  1. First of all, get the most updated version of GoogleTest from the Subversion repository (you need Subversion installed):

    cd ~
    
    svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only
    
  2. Then, build the library (you need cmake installed):

    mv googletest-read-only googletest
    
    mkdir googletest/lib
    
    cd googletest/lib
    
    cmake ..
    
    make
    
  3. At this point:

    • compiled libraries are in the ~/googletest/lib directory
    • include files are in the ~/googletest/include directory

To use googletest:

  1. Include the header in your files:

    #include "gtest/gtest.h"
    
  2. Export the library path:

    export GOOGLETESTDIR=~/googletest
    
  3. Compile with

    g++ ... -I$GOOGLETESTDIR/include -L$GOOGLETESTDIR/lib -lgtest -lpthread
    
like image 85
Claudio Avatar answered Oct 16 '22 05:10

Claudio