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

posted @   Rabbit_Dale  阅读(4500)  评论(2编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示