Google的开源C++单元测试框架Google Test,简称gtest,可以用于多个平台,包括xcode,今天就讲讲怎么在xcode下搭建test环境。
1.提供gest1.7下载地址:http://download.csdn.net/detail/mister_exia/7608947
2.下载并解压,打开../gtest-1.7.0/xcode/gtest.xcodeproj,编译后找到ligtest.a,建议把它copy出来放到一个固定的目录,方便以后别的项目搭建。
3.新建基于控制台的项目测试,首先是把ligtest.a拖入项目中,注意不用copy。
4.设置项目的库目录和头文件目录,分别是ligtest.a的目录和../gtest-1.7.0/include,如下图:
5.修改c++标准库为libstdc++(GNU C++ standard library)
6.将main.m改成main.mm,因为gtest是c++写的。
7.将main函数的第二个参数的const去掉
例子程序:
main.mm
#import <Foundation/Foundation.h>
#include "gtest/gtest.h"
int main(int argc,char * argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
return 0;
}
输出结果:
[==========] Running 0 tests from 0 test cases.
[==========] 0 tests from 0 test cases ran. (0 ms total)
[ PASSED ] 0 tests.
Program ended with exit code: 0