wu

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
1. 从http://code.google.com/p/googletest/ 下载最新的安装文件,我的是gtest-1.6.0.zip   
2. 解压: unzip gtest-1.6.0.zip
3. 安装使用:
    从1.5.0版本开始,放弃使用make install,来安装。我们可以根据README文件里的内容来了解安装方法。
    快速开始:进入make目录,直接make,看到生成了sample1_unittest文件,执行一下看看结果吧!
    在samples文件夹下有一些示例,耐心看一下,很容易就学会使用了。
4. 附录:我的测试环境
    在我的用户目录建立文件夹:gtest_dir,将gtest安装包的include文件夹全部拷贝过来。然后,新建lib文件夹,拷贝刚才在make目录下的gtest_main.a文件至此。
    要编写测试用例,可以自定义Makefile如下:(记得更改GTEST_DIR目录!)
 
# Points to the root of Google Test, relative to where this file is.
# Remember to tweak this if you move this file.
GTEST_DIR = /data/home/neilwu/gtest_dir

# Where to find user code.
USER_DIR = ./

# Flags passed to the preprocessor.
CPPFLAGS += -I$(GTEST_DIR)/include

# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra  

# All Google Test headers.  Usually you shouldn't change this
# definition.
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
                $(GTEST_DIR)/include/gtest/internal/*.h

                

FINALOBJS = $(patsubst ./%.cpp, ./%.o, $(wildcard ./*.cpp))
FINALOBJS += $(patsubst ./%.cc, ./%.o, $(wildcard ./*.cc))

MODULE=Sample

TEST=${MODULE}UnitTest
#if there are any modules that you mocked, add their obj name to MOCKOBJS, so
#they can be rebuilt
#MOCKOBJS += $(TEST) $(BASEDIR)
# House-keeping build targets.

all : $(TEST)

$(TEST): MOCK $(FINALOBJS) 
	$(CXX) $(CXXFLAGS) -lpthread $(FINALOBJS) -o $@ $(GTEST_DIR)/lib/gtest_main.a   

%.o:%.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -g -c -o $@ {1}lt; 
MOCK:
	rm -rf $(MOCKOBJS)
clean:
	rm -f $(FINALOBJS) $(TEST)
 



posted on 2011-11-23 17:20  butterflydog  阅读(583)  评论(0编辑  收藏  举报