2013-03-26 354 views
3

我不是在Objective-C這樣的經歷,但我我想開始使用TDD的iOS開發,爲了這個,我有幾個新手問題:)單元測試

什麼人用於iOS的TDD?我認爲在Xcode中已經使用了Test框架,這是否好?或者更好的選擇?

我試圖做單元測試的一些練習,我創建一個例子,在那裏我有一個TableViewControllerClass,使用CoreLocation,用這種方法:

-(void)startFindLocation 
    { 
     [self.cllManager startUpdatingLocation]; 
    } 

    -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
    { 
     [self.cllManager stopUpdatingLocation]; 
     CLLocation *actualLocation = [locations lastObject]; 

     NSLog(@"latitude: %f", actualLocation.coordinate.latitude); 
     NSLog(@"longitude: %f", actualLocation.coordinate.longitude); 
    } 

我想考,是很簡單,就是查看CLLocation是否有經度和緯度,而不是使用NSLong。 爲此,我真的需要在我的Test Class中分配並初始化這個TableViewController類?或者有任何框架,類似於Rspec(例如,ruby/rails),我可以檢查應用程序屏幕中的特定標籤是否具有此經度和緯度值?

問候

回答

2

我有一系列的iOS上的TDD截屏,開始http://qualitycoding.org/objective-c-tdd/

關於你提到的具體的問題,單元測試需要檢查結果的三種方式之一:

  1. 返回值驗證
  2. 狀態驗證
  3. 動作驗證

我在-locationManager:didUpdateLocations中看不到任何內容:導致其中任何一種情況。也許你想改爲TDD輔助方法。