2011-04-20 53 views
1

我是iPhone開發新手。我已經整合了框架GHUnitIOS來測試我的應用程序。但我還沒有找到關於如何實現單元測試的文檔(這是我第一次在單元測試中)。GHUnit單元測試

有人可以幫我開始GHUnit,文件,例子,解釋?

回答

4

下面是如何配置一個新的目標與GHUnit運行測試:

  • 下載GHUnitIOS framework。請注意名稱,請勿下載適用於OS X的名稱。

  • 將新的目標添加到您的項目中。

  • 添加以下框架: GHUnitIOS.frameworkCoreGraphics.frameworkFoundation.frameworkUIKit.frameworkCoreLocation.framework

  • 生成設置>其他鏈接 標誌添加-ObjC-all_load

  • 編輯...-Info.plist與文本編輯器,你的目標和評論如下:

<!-- 
<key>NSMainNibFile</key> 
<string>MainWindow</string> 
--> 
  • 添加GHUnitIOSTestMain.m文件到您的項目。
  • 在新目標的構建設置中,刪除文件main.m
  • 在爲您的新目標.PCH文件添加#import <GHUnitIOS/GHUnit.h>

現在添加一個測試:

// this import is already in the pch 
// #import <GHUnitIOS/GHUnit.h> 

@interface MyTest : GHTestCase { } 
@end 


@implementation MyTest 

- (void)testFoo { 
    // assert that foo is not nil 
    GHAssertNotNULL(foo, @"foo was nil"); 
} 

@end 

你的測試方法應與test開始。您還可以添加其他方法,如setUp,tearDown,setUpClass,tearDownClass以及一些GHAssertxxx聲明。