How to install Gtest On MacOS and Xcode(如何在MacOS上安装gtest以及XCode使用gtest)

Stella ·
更新时间:2024-11-10
· 611 次阅读

How to install Gtest On MacOS git clone https://github.com/google/googletest.git cd googletest makedir build && cd build cmake -DCMAKE_CXX_STANDARD=17 .. make sudo make install ######test mkdir gtestDemo vi CMakeList.txt echo “export CPLUS_INCLUDE_PATH=/usr/local/include" >> ~/.zshrc echo "export LIBRARY_PATH=/usr/local/lib" >> ~/.zshrc source ~/.zshrc #tell terminal there are new variables #CMakeList.txt cmake_minimum_required(VERSION 3.0) set(CMAKE_CXX_STANDARD 17) project(demo) find_package(GTEST REQUIRED) add_executable(${PROJECT_NAME} main.cpp) target_link_libraries(${PROJECT_NAME} ${GTEST_LIBRARIES}) #main.cpp #include #include 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(2, 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(); } cmake . make ./demo #you can also use the g++ command g++ -std=c++11 -stdlib=libc++ main.cpp -o main Xcode 中的使用

click the workspace and set like this, but the path you should replace by yourself.(if you install follow the step,you could not change it.)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Conference

http://hack.limbicmedia.ca/installing-google-test/
https://blog.csdn.net/v55538679/article/details/77824214


作者:qq_33265800



macOS AND TO ON xcode install

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章
Isoke 2020-03-25
852