linux 下gtest 安装

cd gtest_dir  //解压后的目录
 
mkdir mybuild       # Create a directory to hold the build output.
cd mybuild
cmake ${GTEST_DIR}  # Generate native build scripts.

//If you want to build Google Test's samples, you should replace the last command with

cmake -Dgtest_build_samples=ON ${GTEST_DIR}
make
make install


測试程序
#include "gtest/gtest.h"
int max(int a, int b)
{
return a>b?a:b;
}


TEST(foo, max)
{
EXPECT_EQ(2, max(2,-1));
EXPECT_EQ(3, max(2,3));
}

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}


g++ -g foo_test.cpp -o foo_test -I/home/xunw/gtest-1.6.0/include -L /home/xunw/gtest-1.6.0/mybuild -lgtest -lgtest_main -lpthread
注意-I不能有空格 -L 须要有空格


posted @ 2017-05-03 14:59  lytwajue  阅读(2132)  评论(0编辑  收藏  举报