1、下载googletest
? ? ? ?介绍:现在的googletest软件包分两部分,一部分是gtest,单元测试框架,实现对单元测试用例的管理和设计,另一部分是gmock,实现打桩功能,这两个可以结合起来使用,当然如果不使用gmock,只是用googletest也可以。我就不喜欢gmock进行打桩,它使用起来太麻烦,而是使用自己实现的函数hook方式的函数拦截,这样更直接了当,相率高。
? ? 下载官网:GitHub - google/googletest: GoogleTest - Google Testing and Mocking Framework
2、用cmake生成makefile
进入到googtest目录:
seaside@seaside-VirtualBox:~/Downloads/googletest-release-1.11.0$ cd googletest/
?先进行cmake
cmake CMakeLists.txt
这一步会报错?
CMake Error at CMakeLists.txt:132 (set_target_properties):
set_target_properties called with incorrect number of arguments.
CMake Error at CMakeLists.txt:134 (set_target_properties):
set_target_properties called with incorrect number of arguments.
-- Configuring incomplete, errors occurred!
?是因为没有指定gtest的版本号,我们在CMakeLists.txt文件中增加一行:
set(GOOGLETEST_VERSION 1.11.0)
重新执行
cmake CMakeLists.txt
结果通过:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/seaside/Downloads/googletest-release-1.11.0/googletest
3、编译
seaside@seaside-VirtualBox:~/Downloads/googletest-release-1.11.0/googletest$ make
Scanning dependencies of target gtest
[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 50%] Linking CXX static library lib/libgtest.a
[ 50%] Built target gtest
Scanning dependencies of target gtest_main
[ 75%] Building CXX object CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library lib/libgtest_main.a
[100%] Built target gtest_main
4、安装
将lib目录下的静态库和include头文件拷贝到系统目录下
|