用 GHUnit 运行 ASIHttpRequest 的测试案例

fmms 12年前
     <p>下载ASIHttpResquest后,打开iPhone工程,你会发现在Tests组下有许多.m/.h文件,这是作者用GHUnit框架编写的 测试案例。而且工程中也建立了一个target,名为Tests,显然是为了编译运行测试案例而配置的。但你却无法编译这个target,因为 GHUnitIOS.framework不存在。要想运行这些测试案例,我们还必须做一些额外的工作(以Xcode3.23为例)。</p>    <p>首先,下载GHUnit。该项目主页是:</p>    <p><a href="/misc/goto?guid=4959500530164843413" rel="nofollow">https://github.com/gabriel/gh-unit#readme</a></p>    <p>下载,解压后得到GHUnitIOS.framework。把它复制到ASIHttpRequest的External/GHUnit目录下。</p>    <p>确认在Tests的linked Binary Libraries下有以下内容:</p>    <p>GHUnitIOS.framework</p>    <p>CoreGraphics.framework</p>    <p>Foundation.framework</p>    <p>UIKit.framework</p>    <p>确认Tests的Build设置中,Framework Search Paths设置为GHUnitIOS.framework目录。</p>    <p>确认Tests的Build设置中,Other Linker Flag设置中包含-ObjC和-all_load。</p>    <p>把Tests-info.plist中的Main nib file base name一行删除。</p>    <p>确认项目中已加入GHUnitIOSTestMain.m文件,并已包含在Tests中。该文件下载地址:</p>    <p><a href="/misc/goto?guid=4959500529272874434" rel="nofollow">http://github.com/gabriel/gh-unit/blob/master/Project-iOS/GHUnitIOSTestMain.m</a></p>    <p>确认所编写的测试案例中已包含:     <ghunit ghunit.h=""></ghunit></p>    <p>选择Targets下的Tests,右键->Build “Tests”。在左上角的Build Configure中选择Active Target为Tests,然后点“Buildand Run”,程序运行效果如下:</p>    <p><img style="cursor:pointer;" alt="用 GHUnit 运行 ASIHttpRequest 的测试案例" src="https://simg.open-open.com/show/4c1e29e9e884a50dd5c462336fbbce52.png" width="389" height="750" /> </p> 程序列出了所有测试案例,点击右上角的Run按钮,将运行所有测试案例。如果选择一个测试案例,比如ClientCertificateTests类的 testClientCertificate方法,在点击Re-run按钮,则会单独运行该案例。在控制台窗口可以查看该案例是否通过测试:    <p><strong>2011-09-15 11:40:16.236 Tests[996:207]ClientCertificateTests/testClientCertificate ✔ 3.09s</strong></p>    <p>右侧的勾号表明该测试通过,并列出测试所用时间。</p>    <p>文章出处:<a href="/misc/goto?guid=4959500530281932524" rel="nofollow">http://blog.csdn.net/kmyhy/article/details/6778193</a></p>