Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 创建UITextView时OCUnit崩溃_Objective C_Unit Testing_Uitextview_Ocunit - Fatal编程技术网

Objective c 创建UITextView时OCUnit崩溃

Objective c 创建UITextView时OCUnit崩溃,objective-c,unit-testing,uitextview,ocunit,Objective C,Unit Testing,Uitextview,Ocunit,目前,单元测试正在按bucketload处理简单的问题。我试图在BannerAdViewController类上运行测试,但当达到以下行时,一切都崩溃了: UITextView *buyAppTextView = [[UITextView alloc] initWithFrame:CGRectMake(8, 2, 304, 50)]; 控制台输出如下所示: -[__NSCFType markupDescription]: unrecognized selector sent to insta

目前,单元测试正在按bucketload处理简单的问题。我试图在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

经过广泛的谷歌搜索,并通过一些相关的线程跟踪,我(有点惊讶)设法解决了这个问题。问题源于创建项目时未设置测试目标这一事实。因为它是基于一个Cocos2D模板的,所以我不得不自己添加它。这样做时,我没有将测试目标的构建设置与应用程序挂钩

我必须将以下两个标志添加到测试目标的构建设置中,测试现在可以正常运行:

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

您是否在异常上设置了断点以便查看谁在调用什么?是的,11[SenTestCase invokeTest]->10[NORBannerAdViewTests setup]->9[NORBannerAdViewController init]->8[NORBannerAdView setup]->7[UITextView initWithFrame:]0|halt调用
initWithFrame:
没有问题,所以我怀疑这是一个错误的线索。我认为这一切归结为UIKit/OCUnit不兼容。我已经确认崩溃发生在init和initWithFrame上。(如果我分开alloc和init调用,它仍然会在init崩溃)。此外,如果在代码前面添加另一个带有init调用的UITextView,它也会在这里崩溃。我想我可能需要深入研究测试目标的构建设置(黑魔法)。谢谢你!