1. Introduction
Google C++ Testing Framework: Google C++测试框架
Feature
(1) Google's framework for writing C++ tests on a variety of platforms
Mac OS X
Windows
Cygwin
Windows CE
Symbian
(2) Based on the xUnit architecture
(3) Supports automatic test discovery, a rich set of
Assertions
user-defined assertions
death tests
fatal and non-fatal failures
value- and type-parameterized tests
various options for running the tests
XML test report generation
Google Test is an excellent xUnit style c++ unit testing framework. It is highly recommended. One (minor) drawback of Google Test is it's text based UI, and this project attempts to help.
本系列的文章,均以gtest-1.5.0为例。在Linux平台下,假设源代码在/usr/src/gtest-1.5.0目录;在Win32平台下,假设源代码在E:/opensource/gtest-1.5.0目录。
2. Compile & install
2.1 Linux platform
# cd /usr/src
# wget http://googletest.googlecode.com/files/gtest-1.5.0.tar.gz
# tar -zxvf gtest-1.5.0.tar.gz
# cd gtest-1.5.0
# ./configure
# make
# make install
安装到系统的静态库、共享库,头文件,如下。
# ls /usr/local/lib/libgtest (按2次tab键)
libgtest.a libgtest_main.so libgtest.so.0
libgtest.la libgtest_main.so.0 libgtest.so.0.0.0
libgtest_main.a libgtest_main.so.0.0.0
libgtest_main.la libgtest.so
# ls /usr/local/include/gtest/ (按2次tab键)
gtest-death-test.h gtest-param-test.h gtest-spi.h internal/
gtest.h gtest_pred_impl.h gtest-test-part.h
gtest-message.h gtest_prod.h gtest-typed-test.h
2.2 Win32 platform
../msvc目录下有两种版本,单线程调试版和多线程调试版,打开gtest.sln和gtest_md.sln工程文件,分别build,生成的文件分别如下。
../msvc/gtest/debug/gtest_maind.lib
../msvc/gtest/debug/gtest_prod_test.exe
../msvc/gtest/debug/gtest_unittest.exe
../msvc/gtest-md/Debug/gtest_main-mdd.lib
../msvc/gtest-md/Debug/gtest_prod_test.exe
../msvc/gtest-md/Debug/gtest_unittest.exe
该版本的build没有提供在build后将生成的.lib文件拷贝到lib目录,故,需要手动拷贝。
在..(gtest-1.5.0根目录)目录下建立lib目录,将生成的gtest_maind.lib和gtest_main-mdd.lib拷贝到其中,文件如下。
../lib/gtest_maind.lib
../lib/gtest_main-mdd.lib
目的,是方便在Win32平台下使用。
Reference
http://code.google.com/p/googletest
Technorati 标签: 单元测试; google test
