google test 环境搭建
本文介绍google test在我电脑上的安装配置,环境为widows7 64bit, qt open source, 编译器mingw32, cmake 3,8从https://github.com/google/googletest 下载googletest软件,解压配置cmake, 在source code和'where to build the binaries'里选择你的实际
·
本文介绍google test在我电脑上的安装配置,环境为widows7 64bit, qt open source, 编译器mingw32, cmake 3,8
- 从https://github.com/google/googletest 下载googletest软件,解压
- 配置cmake, 在source code和'where to build the binaries'里选择你的实际目录, 点击configure, generate按钮, 我用的是免费的Mingw,请按实际情况选择
- 配置好的话,会生成makefile, 接下来去执行make:
4 安装gtest库(可选),为了工程在不同机器上少折腾,使用一个环境变量来保存gtest位置,我把文件都复制到
C:\Program Files (x86)\googletest, 然后用GTEST_ROOT指向它
5 验证是否可用。用qt creator新建一个plain c++ project. gtesthello.pro
pro 文件内容如下:
TEMPLATE=app
CONFIG+=consolec++11
CONFIG-=app_bundle
CONFIG-=qt
INCLUDEPATH+=$$(GTEST_ROOT)/include
SOURCES+=main.cpp\
test_hello.cpp
LIBS+=-L$$(GTEST_ROOT)/lib\
-lgtest\
-lgtest_main
#include"gtest/gtest.h"
intmain(intargc,char*argv[])
{
::testing::InitGoogleTest(&argc,argv);
returnRUN_ALL_TESTS();
}
#include"gtest/gtest.h"
TEST(SquareRootTest,PositiveNos){
EXPECT_EQ(3,(1+2));
}
编译运行,结果如下
更多推荐
已为社区贡献1条内容
所有评论(0)