2011-11-30 92 views
0

去寫作的iOS應用程序的測試我想寫基礎上,iPhoneUnitTests蘋果開發站點例子爲我的應用中的一些應用測試。特別是我在通過應用程序中的元素「點擊」時遇到問題,也就是模擬使視圖控制器看起來消失的點擊調用方法。,圍繞應用

比如我有這樣的測試:

- (void)testAddMeal 
{ 
    HomeScreenController *hsCtrl = (HomeScreenController*)mainViewController; 
    [hsCtrl tableView:hsCtrl.tblView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 
    nutritionStrategyController = (NutritionStrategyController*)((UINavigationController*)mainViewController.modalViewController).topViewController; 
    [nutritionStrategyController tableView:nutritionStrategyController.tblView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; 
} 

打開一個第一UIViewController中選擇一個表格單元格,然後第二個UIViewController中應該出現在新的UIViewController中選擇一個表格單元格。 問題是,測試失敗,此錯誤:

Unknown.m:0: error: -[NutritionStrategyTests testAddMeal] : Attempting to begin a modal transition from <UINavigationController: 0x113a2fc0> to <NewMealTrackingController: 0x9353090> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed 

所以我的問題是,我該如何創建這樣的測試?

回答

0

單元測試用於測試代碼,類,模塊等特定位的行爲。如果您想自動化用戶輸入,它是一種不同類型的測試,您可以查看UIAutomation instrument,專門爲此測試類型。

The Automation instrument, guided by your test scripts, exercises the user interface elements of your application, allowing you to log the results for your analysis. The Automation feature can simulate many user actions supported by devices that support multitasking and run iOS 4.0 or later. Your test script can run both on the iOS device and in the iOS Simulator without modification.

An important benefit of the Automation instrument is that you can use it with other instruments to perform sophisticated tests such as tracking down memory leaks and isolating causes of performance problems.