美文网首页
gtest安装、编译和使用

gtest安装、编译和使用

作者: geofer | 来源:发表于2017-10-27 12:46 被阅读0次
    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 <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

    相关文章

      网友评论

          本文标题:gtest安装、编译和使用

          本文链接:https://www.haomeiwen.com/subject/pkmrpxtx.html