Skip to content

Instantly share code, notes, and snippets.

@Shitaibin
Last active March 9, 2017 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shitaibin/7426898bcb9f15f59739616e770475aa to your computer and use it in GitHub Desktop.
Save Shitaibin/7426898bcb9f15f59739616e770475aa to your computer and use it in GitHub Desktop.
Install Google Test
## unzip and go into googletest directory
➜ Downloads unzip googletest-master.zip
Archive: googletest-master.zip
aa148eb2b7f70ede0eb10de34b6254826bfb34f4
creating: googletest-master/
...
inflating: googletest-master/travis.sh
➜ Downloads
➜ Downloads ls
googletest-master googletest-master.zip pixman_0.30.2.orig.tar.gz redis-3.2.0 redis-3.2.0.tar.gz
➜ Downloads mv googletest-master gtest-1.7
➜ Downloads ls
googletest-master.zip gtest-1.7 pixman_0.30.2.orig.tar.gz redis-3.2.0 redis-3.2.0.tar.gz
➜ Downloads cd gtest-1.7
➜ gtest-1.7 ls
appveyor.yml CMakeLists.txt googlemock googletest README.md travis.sh
➜ gtest-1.7 cd googletest
➜ googletest ls
build-aux cmake codegear CONTRIBUTORS include m4 Makefile.am README.md scripts test
CHANGES CMakeLists.txt configure.ac docs LICENSE make msvc samples src xcode
## generate Makefile by using CMake
➜ googletest mkdir build
➜ googletest cd build
➜ build cmake -Dgtest_build_samples=ON -Dgtest_build_tests=ON ..
-- The CXX compiler identification is GNU 4.9.2
...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/a/Downloads/gtest-1.7/googletest/build
➜ build ls
CMakeCache.txt CMakeFiles cmake_install.cmake CTestTestfile.cmake Makefile
## build google test
➜ build make
Scanning dependencies of target gtest
[ 1%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.o
Linking CXX static library libgtest.a
...
[100%] Built target sample9_unittest
## build google test cases
➜ build make test
Running tests...
Test project /home/a/Downloads/gtest-1.7/googletest/build
Start 1: gtest-death-test_test
1/41 Test #1: gtest-death-test_test .............. Passed 0.38 sec
Start 2: gtest_environment_test
...
100% tests passed, 0 tests failed out of 41
Total Test time (real) = 11.55 sec
➜ build ls
CMakeCache.txt gtest_no_rtti_unittest gtest_xml_outfile1_test_
...
## run a test case
➜ build ./sample1_unittest
Running main() from gtest_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
...
[==========] 6 tests from 2 test cases ran. (0 ms total)
[ PASSED ] 6 tests.
## find libgest.a
➜ build find . -name '*.a' -print
./libgtest_main_no_exception.a
./libgtest_main.a
./libgtest_no_exception.a
./libgtest_main_use_own_tuple.a
./libgtest.a
./libgtest_main_no_rtti.a
## install google test
➜ build sudo mkdir /usr/local/gtest
[sudo] password for a:
➜ build sudo cp libgtest.a /usr/local/gtest
➜ build sudo ln -snf /usr/local/gtest/libgtest.a /usr/local/lib/libgtest.a
➜ build ls
➜ build cd ..
➜ googletest sudo cp -r include /usr/local/gtest
➜ googletest sudo ln -snf /usr/local/gtest/include/gtest /usr/local/include/gtest
➜ googletest ll /usr/local/include/gtest
lrwxrwxrwx 1 root root 30 Mar 9 13:12 /usr/local/include/gtest -> /usr/local/gtest/include/gtest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment