-
Ubuntu Linux x86_64
-
g++ 4.8+
-
If cmake is not installed in your system, install it via the command:
$ sudo apt-get install cmake
-
MingW with MSYS (Windows only)
$ git clone https://github.com/google/googletest.git
$ 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
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.
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.
TBD