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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM