单元测试目前正在通过大量的负载来处理简陋的馅饼。我正在尝试在我的 BannerAdViewController 类上运行测试,但是当到达以下行时一切都崩溃了:
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