google test简介

本文介绍了Google C++测试框架Google Test,它基于xUnit架构,支持多种平台,包括自动测试发现、丰富的断言、死亡测试等功能。文章以gtest-1.5.0为例,详细说明了在Linux和Win32平台上如何编译和安装Google Test,并提供了相关参考资料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本博客 http://blog.youkuaiyun.com/livelylittlefish 贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!

1. Introduction

 

Google C++ Testing Framework: Google C++测试框架

 

Feature

(1) Google's framework for writing C++ tests on a variety of platforms

Linux

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 (2tab)

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/ (2tab)

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.slngtest_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.libgtest_main-mdd.lib拷贝到其中,文件如下。

 

../lib/gtest_maind.lib

../lib/gtest_main-mdd.lib

 

目的,是方便在Win32平台下使用。

 

 

Reference

http://code.google.com/p/googletest



Technorati 标签:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值