参考博客
MacOS
https://www.bilibili.com/video/BV1BB4y147Nv/?spm_id_from=333.337.search-card.all.click&vd_source=24b90a03ecfc31d2ef34160f32363f2c https://www.jianshu.com/p/68b9d2682cddLinux
https://www.cnblogs.com/yanqingyang/p/12732087.html代码仓库
https://github.com/google/googletest安装展示
MacOS
命令行输入
git clone http://github.com/google/googletest cd googletest mkdir build && cd build cmake -DCMAKE_CXX_STANDARD=17 .. make make installView Code
截图展示
cmake -DCMAKE_CXX_STANDARD=17 ..View Code
makeView Code
make installView Code
检查是否成功安装好
ls /usr/local/lib/pkgconfig/*test* # 如果成功下载后,就会在 /usr/local/lib/pkgconfig/下出现 test测试代码
Linux
命令行
git clone https://github.com/google/googletest.git cd googletest mkdir build cd build cmake .. make sudo make install全部命令
cmake ..View Code
makeView Code
sudo make installView Code
测试
创建Demo —— CLion项目
CMakeList.txt文件
cmake_minimum_required(VERSION 3.0) set(CMAKE_CXX_STANDARD 11) project(demo) find_package(GTEST REQUIRED) add_executable(${PROJECT_NAME} test/main.cpp) target_link_libraries(${PROJECT_NAME} ${GTEST_LIBRARIES})CMakeList.txt
main.cpp
#include <iostream> #include <gtest/gtest.h> int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } // case1 TEST(test, c1) { EXPECT_EQ(3, add(1, 2)); EXPECT_EQ(12, add(6, 6)); } // case2 TEST(test, c2) { EXPECT_EQ(-1, sub(1, 2)); } GTEST_API_ int main(int argc, char ** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }Main.cpp
成功运行结果
标签:MacOS,Code,int,make,googletest,GoogleTest,Linux,com,View From: https://www.cnblogs.com/Osea/p/17858129.html