Centos下配置单元测试工具gtest

时间:2024-04-23 01:08:30

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

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

配置过程如下:

1、解压gtest-1.6.0

Centos下配置单元测试工具gtest

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

Centos下配置单元测试工具gtest

3、测试程序运行如下:

Centos下配置单元测试工具gtest

4、新建一个文件夹,gtest_program,将gtest-1.6.0中的include文件拷过来。Centos下配置单元测试工具gtest

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

Centos下配置单元测试工具gtest

6、编写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 = /home/anker/gtest_program # 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)

7、测试结果如下:

Centos下配置单元测试工具gtest

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