目前,单位测试是通过铲斗来处理不起作用的。我正在尝试在我的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
答案 0 :(得分:3)
经过广泛的谷歌搜索,并通过一些相关的线程跟踪我(有点令人惊讶)设法解决问题。问题源于在创建项目时未设置测试目标的事实。由于它是基于Cocos2D模板之一,我不得不自己添加它。这样做,我没有使用App连接测试目标的构建设置。
我必须在test-target的构建设置中添加以下两个标志,现在测试运行良好:
Bundle Loader: $(BUILT_PRODUCTS_DIR)/AppName.app/AppName
Test Host: $(BUNDLE_LOADER)