环境: win7/win10+qt5.8.0(MinGW),
1.gtest获取: 从:https://www.bogotobogo.com/cplusplus/google_unit_test_gtest.php
获取gtest-1.7.0-rc1.zip,下载链接,下载打包的源码
或在git仓库下载: git clone https://github.com/google/googletest.git
2.解压gtest-1.7.0;在Qt创建一个静态C++库项目,将生成的Qt project文件拷贝到gtest-1.7.0目录下,命名为:gtest.pro;
3.编辑gtest.pro:主要添加源文件(SOURCES)信息和包含信息如下:
SOURCES += src/gtest_main.cc\
src/gtest.cc\
......
(所有src目录下所有源文件)
INCLUDEPATH += ./include
TEMPLATE +=lib
代码如下:
1 #------------------------------------------------- 2 # 3 # Project created by QtCreator 2019-04-24T17:05:02 4 # 5 #------------------------------------------------- 6 7 QT -= gui 8 9 TARGET = gtest 10 TEMPLATE = lib 11 CONFIG += staticlib 12 INCLUDEPATH +=./include 13 14 # The following define makes your compiler emit warnings if you use 15 # any feature of Qt which as been marked as deprecated (the exact warnings 16 # depend on your compiler). Please consult the documentation of the 17 # deprecated API in order to know how to port your code away