1.下载编译gtest,地址:https://github.com/google/googletest.git
2.找到gtext文件夹下msvc文件夹,vs打开,编译静态库,运行时库貌似要选择/MD动态链接,不然后续使用会出问题
3.将include,编译好的lib库放在一个项目经常使用的位置,可以设置个环境变量
4.创建Qt控制台程序,选择QTest,QtCore,QtGui。将mian下QCoreApplication改为QApplication
#include <QApplication>
#include <gtest/gtest.h>
int main(int argc, char *argv[])
{
std::cout << "unittest start!" << std::endl;
QApplication a(argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5.项目管理中引入gtest.lib。
6.需要UI测试的地方使用QTest,其它判断都是用gtest的