Skip to content

Latest commit

 

History

History
98 lines (82 loc) · 2.4 KB

googletest_setup.md

File metadata and controls

98 lines (82 loc) · 2.4 KB

Google Test framework Setup Guide

Requirements

  • Ubuntu Linux x86_64

  • g++ 4.8+

  • CMake

    If cmake is not installed in your system, install it via the command:

    $ sudo apt-get install cmake
  • MingW with MSYS (Windows only)

Steps of install on Linux

Get the google test repo:

$ git clone https://github.com/google/googletest.git

Compile Google Test static library :

$ cd googletest
$ cmake CMakeLists.txt
$ make

By default, 2 static library files will be generated:

  • googlemock/gtest/libgtest.a
  • googlemock/gtest/libgtest_main.a
  • googlemock/libgmock.a
  • googlemock/libgtest_main.a

Google Test Library Demo

New a gtest.cpp, with the following content:

#include <gtest/gtest.h>
TEST(MathTest, TwoPlusTwoEqualsFour) {
    EXPECT_EQ(2 + 2, 4);
}

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

Compile it:

$ g++ -I<path/to/googletest/include> gtest.cpp <path/to/libgtest.a> -o gtest
$ ./gtest

Run it, you will get the message:

[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from MathTest
[ RUN      ] MathTest.TwoPlusTwoEqualsFour
[       OK ] MathTest.TwoPlusTwoEqualsFour (0 ms)
[----------] 1 test from MathTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.

Google Mock Library Demo

Compile it:

$ g++ -I<path/to/googletest/include> -I<path/to/googlemock/include> HelloWorldTest.cpp HelloWorld.cpp <path/to/libgmock_main.a> -o gmock
$ ./gmock

Run it, you will get the message:

Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from HelloWorldTest
[ RUN      ] HelloWorldTest.getMessage
[       OK ] HelloWorldTest.getMessage (0 ms)
[----------] 1 test from HelloWorldTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.

Steps of install on Windows

TBD