gtest安装、编译和使用

  1. download froom: wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz
  2. 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
  1. 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/

  1. env
    edit your path
    add GTEST_HOME env
    update path, append include
    update ld_library_path, append lib

  2. how to use

  • vim gtest_demo.c
#include 
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

你可能感兴趣的:(gtest安装、编译和使用)