Centos下配置单元测试工具gtest

gtest是google提供的一个非常强大的单元测试工具,下载地址:https://code.google.com/p/googletest

我下载的是gtest-1.6.0.拷贝到Centos系统上面。参考:http://blog.csdn.net/butterflydog/article/details/7005045

配置过程如下:

1、解压gtest-1.6.0

2、查看文件内容,找到make文件,进行make,生成一个测试程序,包含gtest_main.a文件

3、测试程序运行如下:

4、新建一个文件夹,gtest_program,将gtest-1.6.0中的include文件拷过来。

5、在gtest_program中新建一个lib文件夹,将gtest-1.60中的make文件夹中新生成的gtest_main.a文件拷贝过来。

6、编写Makefile,一定要记得修改GTEST_DIR为自己的路径名。如下:

 1 # Points to the root of Google Test, relative to where this file is.
 2 # Remember to tweak this if you move this file.
 3 GTEST_DIR = /home/anker/gtest_program
 4 
 5 # Where to find user code.
 6 USER_DIR = ./
 7 
 8 # Flags passed to the preprocessor.
 9 CPPFLAGS += -I$(GTEST_DIR)/include
10 
11 # Flags passed to the C++ compiler.
12 CXXFLAGS += -g -Wall -Wextra  
13 
14 # All Google Test headers.  Usually you shouldn't change this
15 # definition.
16 GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
17                 $(GTEST_DIR)/include/gtest/internal/*.h
18 
19                 
20 
21 FINALOBJS = $(patsubst ./%.cpp, ./%.o, $(wildcard ./*.cpp))
22 FINALOBJS += $(patsubst ./%.cc, ./%.o, $(wildcard ./*.cc))
23 
24 MODULE=Sample
25 
26 TEST=${MODULE}UnitTest
27 #if there are any modules that you mocked, add their obj name to MOCKOBJS, so
28 #they can be rebuilt
29 #MOCKOBJS += $(TEST) $(BASEDIR)
30 # House-keeping build targets.
31 
32 all : $(TEST)
33 
34 $(TEST): MOCK $(FINALOBJS) 
35     $(CXX) $(CXXFLAGS) -lpthread $(FINALOBJS) -o $@ $(GTEST_DIR)/lib/gtest_main.a   
36 
37 %.o:%.cpp
38     $(CXX) $(CPPFLAGS) $(CXXFLAGS) -g -c -o $@ {1}lt; 
39 MOCK:
40     rm -rf $(MOCKOBJS)
41 clean:
42     rm -f $(FINALOBJS) $(TEST)
43  

7、测试结果如下:

参考:http://www.cnblogs.com/chutianyao/archive/2012/12/01.html

转载于:https://www.cnblogs.com/Anker/p/3203477.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值