How to install and use GTest on Ubuntu

Install GTest on Ubuntu

sudo apt-get install libgtest-dev
sudo apt-get install cmake # install cmake
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make

# copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder
sudo cp *.a /usr/lib

Create CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

# Locate GTest
find_package(GTest REQUIRED)

# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests tests.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)


#include "../libril-gto-sqn/at_tok.c"
#include "../libril-gto-sqn/ril-main-gen.c"

#include <gtest/gtest.h>

class test_class {
        int test_method(int a, int b) {
        return a + b;

TEST( test_class_tests, test_case )
    test_class test_object;

    ASSERT_EQ( test_object.test_method(2, 2), 5 );

int main(int argc, char **argv) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();

Make and run tests

cmake CMakeLists.txt

Getting started with Google Test (GTest) on Ubuntu


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s