iOS测试-GHUnit配置

本文介绍了iOS测试中使用的GHUnit框架,对比了它与OCUnit的区别,并详细阐述了如何在Xcode 5及更高版本中配置GHUnit测试目标。包括创建测试目标、链接库以及设置Objective-C类别等步骤。

前一段时间一直在看iOS测试相关的知识以及测试框架、测试工具的使用,现在拿来总结以下。

GHUnit 是iOS单元测试的一个开源框架,它与XCode集成的OCUnit测试框架有着很大的不同。OCUnit测试框架是集成在你的项目目录中的,而GHUnit测试框架是单独存在的一个target,可以独立运行,并且有UI界面;另外GHUnit是开源的,也意味着你可以根据测试计划自定义框架功能,提高你的测试效率。

那么首先我们先从GHUnit测试框架的配置入手:参考官方文档:http://gh-unit.github.io/gh-unit/docs/appledoc_include/guide_install_ios_7.html,官方文档中的开发环境是Xcode 5,现在已经更新的Xcode7,但是基本的配置步骤是没有太大的区别。

Installing in iOS (Xcode 5)

To use GHUnit in your project, you’ll need to create and configure a test target.

Create Test Target

  • You’ll want to create a separate Test target. Select the project file for your app in the Project Navigator. From there, select the “Add Target…” button in the right window.

Add Target

  • Select iOS, Application, Empty Application. Select Next.

Select Application

  • Name it Tests or something similar. Select Finish.

Name it

Configure the Test Target

  • Select the created Test target and select the tab “Build Phases”. Open the “Link Binary With Libraries” option and click on the “+” button.

Add QuartzCore

  • Select QuartzCore.framework and click “Add”.

  • Download GHUnitIOS.framework and unzip it in your Test Target directory (a subdirectory of your project directory).

  • Select the created Test target and select the tab “Build Phases”. Open the “Link Binary With Libraries” option and click on the “+” button.

Add Framework

  • Click “Add Other…”.

Add Framework Dialog

  • Select the GHUnitIOS.framework from your Test Target directory.

  • We want to enable use of Objective-C categories, which isn’t enabled for static libraries by default. In the Tests target, Build Settings, under Other Linker Flags, add -ObjC.

Other Linker Flags

  • Select and delete the files from the existing Tests folder. Leave the Supporting Files folder. GHUnit will provide the application delegate below.

Remove Test Files

  • In Tests folder, in Supporting Files, main.m, replace the last argument of UIApplicationMain with @"GHUnitIOSAppDelegate". Remove the #import "AppDelegate.h" if present.

Main Method

  • Select the Tests target, iPhone Simulator configuration:

Select Target

  • Hit Run, and you’ll hopefully see the test application running (but without any tests).

Run It


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值