操作系统:fedora15-x86_64
1、下载,解压到/home/hlf,
mv gtest-1.60 gtest
cd gtest
3、ar -rv libgtest.a gtest-all.o
注意:
虽然在目录下有configure,甚至在make目录下有makefile文件等,但都是障眼法。
简单测试:
不妨设我们需要测试foo.h中的一个max函数(求两个数中较大的一个)
foo.h文件内如如下:
撰写测试程序foo_test.cpp来对foo进行测试:
foo_test.cpp文件内如如下:
编译foo_test.cpp,编译命令如下:
需要注意的是,要链接pthread这个库。
测试结果:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from foo
[ RUN ] foo.max
[ OK ] foo.max (0 ms)
[----------] 1 test from foo (1 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (3 ms total)
[ PASSED ] 1 test.