本文介绍google test在我电脑上的安装配置,环境为widows7 64bit, qt open source, 编译器mingw32, cmake 3,8

  1. https://github.com/google/googletest 下载googletest软件,解压
  2. 配置cmake, 在source code和'where to build the binaries'里选择你的实际目录, 点击configure, generate按钮, 我用的是免费的Mingw,请按实际情况选择
  3. 配置好的话,会生成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

main.cpp
#include"gtest/gtest.h"
intmain(intargc,char*argv[])
{
::testing::InitGoogleTest(&argc,argv);
returnRUN_ALL_TESTS();
}

test_hello.cpp

#include"gtest/gtest.h"
TEST(SquareRootTest,PositiveNos){
EXPECT_EQ(3,(1+2));
}

编译运行,结果如下

   

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐