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 須要有空格



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM