Google gTest <I> First things first

Google有一个相当漂亮的project叫做gTest,它的出现为单元测试的构建建立了一个较为易用的framework。

第一次看到gTest的输出,我觉得,这是一个相当舒服的framework。

[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from ListenersTest
[ RUN ] ListenersTest.DoesNotLeak
[ OK ] ListenersTest.DoesNotLeak (0 ms)
[ RUN ] ListenersTest.LeaksWater
[ OK ] ListenersTest.LeaksWater (0 ms)
[----------] 2 tests from ListenersTest (2 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test case ran. (5 ms total)
[ PASSED ] 2 tests.

要使用gTest,就必须从构建它开始,首先可以到google官方(http://code.google.com/p/googletest/)获取gTest的源码,然后就可以根据自己的平台和需求构建自己的环境。参考文档可以在google官方获取,源码里包含的README文件也相当不错。

简要的构建环境步骤:

1)安装必要的工具:cmake 2.6.4 和 python 2.3 以上版本;

2)使用cmake编译出指定的makefile或project,我使用的是"Visual Studio 10",并借此完成库文件的构建(推荐选择debug为默认设置编译);

3)在VS的新工程里添加编译依赖:

Include: Project Property -> Configuration Properties -> C/C++ -> General -> Additional Include Directories

Linker: Project Property -> Configuration Properties -> Linker -> Input -> Additional Dependencies

4)编译新工程(同样需要选择debug),完成后,即可以完成一个gTest支持的测试项目;

简易的构建流程到此就算完成

原文地址:https://www.cnblogs.com/alexxyjiang/p/2056151.html