1 gtest安装
git clone git@github.com:google/googletest.git
cd googletest
cmake .
make
make install
2 使用
2.1 添加cmakelists.txt
cmake_minimum_required(VERSION 3.25)
include_directories("/usr/local/mysql/include")
include_directories("/usr/local/mysql/lib")
set (PROJECT_NAME cpplearn)
PROJECT(${PROJECT_NAME})
set(CMAKE_CXX_STANDARD 14)
find_package(GTEST REQUIRED)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
#add_subdirectory(subprojects/faiss)
#add_subdirectory(subprojects/googletest)
add_executable(cpplearn
hello.cpp)
target_link_libraries(cpplearn ${OpenCV_LIBS})
target_link_libraries(cpplearn "/usr/local/mysql/lib/libmysqlclient.dylib")
target_link_libraries(${PROJECT_NAME} ${GTEST_LIBRARIES})
2.2 代码
#include <iostream>
#include <stdio.h>
#include <mysql.h>
#include <gtest/gtest.h>
using namespace cv;
using namespace std;
int add(int a, int b) {
return a + b;
}
TEST(test, c1) {
EXPECT_EQ(3, add(1, 2));
EXPECT_EQ(12, add(2, 6));
}
int main(int argc, char ** argv)
{
cout << "hello world ! \n" ;
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}