2013-01-03 70 views
1

單元測試正在通過此處的bucketload來處理謙卑。我試圖運行我的BannerAdViewController級測試,但達到以下線的時候一切都轟然倒塌:OCUnit在創建UITextView時崩潰

UITextView *buyAppTextView = [[UITextView alloc] initWithFrame:CGRectMake(8, 2, 304, 50)]; 

控制檯輸出如下:

-[__NSCFType markupDescription]: unrecognized selector sent to instance 0x1bc2de0 

這是它到達的方法發生崩潰之前:

-(void)setup{ 
    _bannerFrame = [self frameRectForBannerAd]; 
    _bannerWrapperFrame = [self frameRectForBannerWrapperFrame]; 

    UITextView *buyAppTextView = [[UITextView alloc] initWithFrame:CGRectMake(8, 2, 304, 50)]; 
    [buyAppTextView setText:@"some text"]; 
    [buyAppTextView setTextColor:[UIColor blackColor]]; 
    [buyAppTextView setFont:[UIFont systemFontOfSize:10]]; 
    [buyAppTextView setAutoresizingMask:UIViewContentModeScaleAspectFit]; 
    [buyAppTextView setUserInteractionEnabled:NO]; 

    _placeHolderBanner = [[UIView alloc] initWithFrame:_bannerFrame]; 

    [_placeHolderBanner setBackgroundColor:[UIColor whiteColor]]; 
    [[_placeHolderBanner layer] setBorderColor:[UIColor blackColor].CGColor]; 
    [[_placeHolderBanner layer] setBorderWidth:1.0]; 
    [_placeHolderBanner addSubview: buyAppTextView]; 

    [[self view] setFrame:_bannerWrapperFrame]; 
    [[self view] setBackgroundColor:[UIColor clearColor]]; 
    [[self view] addSubview: _placeHolderBanner]; 

    _iAdBanner = [[ADBannerView alloc] initWithFrame:CGRectZero]; 

    [[self view] addSubview: _iAdBanner]; 
    _iAdBanner.delegate = self; 
    _iAdBanner.hidden = YES; 
} 

如果我註釋掉了與buyAppTextView有關的所有操作,測試運行正常。 (是的,如果您想知道,測試平臺與UIKit鏈接)。

哦,測試類看起來像這樣

#import "NorBannerAdViewTests.h" 
#import "NORBannerAdViewController.h" 

@implementation NorBannerAdViewTests 

NORBannerAdViewController *_adViewController; 

- (void)setUp{ 
    [super setUp]; 
    _adViewController = [[NORBannerAdViewController alloc] init]; 
} 

- (void)tearDown{ 
    [super tearDown]; 
    [_adViewController release]; 
} 

-(void) testThatFrameRectForBannerAdWrapperDoesNotReturnZero{ 
    CGRect receivedFrame = [_adViewController frameRectForBannerWrapperFrame]; 
    STAssertFalse((CGRectIsEmpty(receivedFrame)), @"receivedFrame should not be zero"); 
} 

-(void) testThatFrameRectForBannerAdDoesNotReturnZero{ 
    CGRect receivedFrame = [_adViewController frameRectForBannerAd];  
    STAssertFalse((CGRectIsEmpty(receivedFrame)), @"receivedFrame should not be zero"); 
} 

@end 
+0

你有沒有設置異常斷點,所以你可以看到誰打電話呢? –

+0

Yup 11 [SenTestCase invokeTest] - > 10 [NORBannerAdViewTests設置] - > 9 [NORBannerAdViewController init] - > 8 [NORBannerAdView設置] - > 7 [UITextView initWithFrame:] | 0_HALT –

+0

'initWithFrame:'調用沒有問題,所以我懷疑這是一個虛假的提示。 –

回答

3

廣泛google搜索後,並通過I(有些奇怪)設法解決這個問題的一些相關的線程進行跟蹤。問題源於創建項目時沒有設置測試目標的事實。由於它基於一個Cocos2D模板,我必須自己添加它。這樣做,我沒有用App連接測試目標的構建設置。

我有以下兩個標誌添加到被測試的構建設置和測試,目前運行良好:

Bundle Loader: $(BUILT_PRODUCTS_DIR)/AppName.app/AppName 
Test Host: $(BUNDLE_LOADER)