- download froom: wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz
- unzip
./googletest-release-1.8.0
├── appveyor.yml
├── CMakeCache.txt
├── CMakeFiles
├── cmake_install.cmake
├── CMakeLists.txt
├── CTestTestfile.cmake
├── googlemock
├── googletest
├── Makefile
├── README.md
└── travis.sh
- compile
$ cd googletest
$ cmake -DBUILD_SHARED_LIBS=ON .
$ make
$ sudo cp -a include/gtest /home/xxx/opt/gtest1.8.0/include
$ sudo cp -a libgtest_main.so libgtest.so /home/xxx/gtest1.8.0/lib/
-
env
edit your path
add GTEST_HOME env
update path, append include
update ld_library_path, append lib -
how to use
- vim gtest_demo.c
#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();
}
- run gtest_demo.c
$ export GTEST_HOME=/home/xxx/opt/gtest1.8.0
$ export LD_LIBRARY_PATH=$GTEST_HOME/lib:$LD_LIBRARY_PATH
$ g++ -I $GTEST_HOME/include -L $GTEST_HOME/lib -lgtest -lgtest_main -lpthread test.cpp
网友评论