XIB网点单元测试 [英] XIB outlets unit testing

查看:86
本文介绍了XIB网点单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来测试视图是否正确配置(除其他外,我将monthScrollview放置为视图的子视图:

I have following code to test if view is properly configured(among others, I have the monthScrollview placed as a subview of view:

@implementation ECBrowserViewControllerTests
-(void)setUp
{
  //-deviceSpecific simply adds suffix like '_iPad'
  main=[[ECBrowserViewController alloc] initWithNibName:[@"ECBrowserViewController" deviceSpecific] bundle:nil];
}
-(void)testOutlets
{
    STAssertNotNil(main.view, @"View outlet not set!");

    STAssertNotNil(main.monthScrollView, @"no month scrollview");
    STAssertTrue(main.monthScrollView.pagingEnabled, @"Paging should be enabled");
}

-(void)testPaging
{
    STAssertNotNil(main.monthScrollView, @"no month scrollview");
    STAssertTrue(main.monthScrollView.pagingEnabled, @"Paging should be enabled");
}
@end

有人能告诉我为什么testPaging失败而testOutlets成功吗?我发现这与首先检查parentView有关,但是为什么呢?

Could any one tell me why the testPaging fails, while testOutlets succeeds? I figured out that's about checking the parentView first, but why?

我正在使用Xcode 4.6.3和内置的SenTestingKit

I'm using Xcode 4.6.3 and builtin SenTestingKit

推荐答案

由于在COCOA中ViewController的视图是懒惰地加载的,因此它只是失败了: 只有在需要时才设置 view 属性,即当人们第一次尝试获取其值时.那时loadView被召唤.

It simply fails because ViewController's views in COCOA are loaded lazily: The view property is not set until it's needed, namely when one tries to fetch its value for the first time. At that moment loadView is summoned.

testPaging测试失败的原因是由于viewController的视图从未被获取.

The reason why your testPaging test fails is due to the fact that the viewController's view in never fetched.

因此,在您的特定测试中,您必须在视图控制器上显式调用-view才能调用其-loadView方法/回调,从而分配其视图(和子视图).

So, in your specific test, you have to explicitly invoke -view over a the view controller in order to have its -loadView method/callback summoned and hence get its view (and subviews) allocated.

这篇关于XIB网点单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆