Xcode 5.1/iOS 7.1中的单元测试问题:BKSEventFocusManager中的断言失败

Xcode 5.1/iOS 7.1中的单元测试问题:BKSEventFocusManager中的断言失败,ios,xcode,ios7.1,xcode5.1,Ios,Xcode,Ios7.1,Xcode5.1,在升级到Xcode 5.1后运行基于XTest的逻辑测试时,如果看到以下错误,您很想知道解决方法 2014-03-11 12:57:42.258 xctest[25605:303] deferral properties must have a clientID 2014-03-11 12:57:42.258 xctest[25605:303] *** Assertion failure in -[BKSEventFocusManager deferEventsForClientWithPro

在升级到Xcode 5.1后运行基于XTest的逻辑测试时,如果看到以下错误,您很想知道解决方法

2014-03-11 12:57:42.258 xctest[25605:303] deferral properties must have a 
clientID 2014-03-11 12:57:42.258 xctest[25605:303] ***
Assertion failure in -[BKSEventFocusManager
deferEventsForClientWithProperties:toClientWithProperties:],
/SourceCache/BackBoardServices_Sim/SpringBoard-2618.99.15/megatrond/BKSEventFocusManager.m:63
<unknown>:0: error: -[CSAPIErrorHandlerTests testDisplayReachabilityAlert] : 
props must have a valid clientID (  
0   CoreFoundation      0x00b251e4 __exceptionPreprocess + 180  
1   libobjc.A.dylib     0x007988e5 objc_exception_throw + 44    
2   CoreFoundation      0x00b25048 +[NSException raise:format:arguments:] + 136     
3   Foundation          0x000114de -[NSAssertionHandler
    handleFailureInMethod:object:file:lineNumber:description:] + 116    
4   BackBoardServices   0x0197fece -[BKSEventFocusManager
    deferEventsForClientWithProperties:toClientWithProperties:] + 154   
5   UIKit               0x07a942e1 -[UIWindow _beginKeyWindowDeferral] + 176    
6   UIKit               0x07a940a7 -[UIWindow _makeKeyWindowIgnoringOldKeyWindow:] + 129    
7   UIKit               0x07a9400d -[UIWindow makeKeyWindow] + 41   
8   UIKit               0x07a943e2 -[UIWindow makeKeyAndVisible] + 91
2014-03-11 12:57:42.258 xctest[25605:303]延迟属性必须具有
clientID 2014-03-11 12:57:42.258 xctest[25605:303]***
-[BKSEventFocusManager]中的断言失败
DeferreEventsForClientWithProperties:toClientWithProperties:],
/SourceCache/BackBoardServices_Sim/SpringBoard-2618.99.15/megatrond/BKSEventFocusManager.m:63
:0:错误:-[CSAPIErrorHandlerTests TestDisplayReachibilitylert]:
道具必须具有有效的clientID(
0 CoreFoundation 0x00b251e4例外预处理+180
1 libobjc.A.dylib 0x007988e5 objc_异常_抛出+44
2 CoreFoundation 0x00b25048+[N异常提升:格式:参数:][136
3基金会0x000 0114DE-[ NSRealStudio处理程序]
handleFailureInMethod:对象:文件:行号:说明::+116
4背板服务0x0197fece-[BKSEventFocusManager
延迟事件ForClientWithProperties:toClientWithProperties:+154
5 UIKit 0x07a942e1-[UIWindow\u BeginkeyWindow延迟]+176
6 UIKit 0x07a940a7-[UIWindow\u makeKeyWindowIgnoringOldKeyWindow:+129
7 UIKit 0x07a9400d-[UIWindow makeKeyWindow]+41
8 UIKit 0x07a943e2-[UIWindow makeKeyAndVisible]+91

我发现重现这种情况的最基本情况如下

#import <XCTest/XCTest.h>

@interface DummyTest : XCTestCase

@end

@implementation DummyTest

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
                                                    message:@"Message"
                                                   delegate:nil
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:nil];

    // Commenting out the next row does not cause the problem
    [alert show];

    XCTAssertTrue(YES);
}

@end
#导入
@接口DummyTest:XCTestCase
@结束
@实现Dummy测试
-(无效)设置{
[超级设置];
//将设置代码放在这里。在调用类中的每个测试方法之前调用此方法。
}
-(无效)拆卸{
//将拆卸代码放在这里。该方法在调用类中的每个测试方法后调用。
[超级撕裂];
}
-(无效)测试示例{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“Title”
信息:@“信息”
代表:无
取消按钮:@“取消”
其他按钮:无];
//注释掉下一行不会导致问题
[警报显示];
Xctasertrue(是);
}
@结束
似乎在测试中显示UIAlertView会导致此问题。这在Xcode 5.0中正常工作,但在Xcode 5.1中被破坏

  • Xcode版本5.1(5B130a)
  • OSX版本10.9.2
如果您遇到此问题,请尝试上面的代码,看看它是否可复制

我用于运行测试用例(在Kiwi中称为Specs)。我可以通过模拟
UIAlertView
、短截取
-show
方法并使用模拟完成测试方法来消除此断言失败

下面是我的代码示例:

[[UIAlertView alloc] stub:@selector(show)];
[[[UIAlertView alloc] should] receive:@selector(initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:)];
[[[UIAlertView alloc] should] receive:@selector(show)];
[sut methodYouWantToTest]; // sut => system under test (self)
编辑: 我还通过将
UIAlertView
作为
UIViewController
的属性来避免断言失败

[sut methodYouWantToTest];
[[[sut alertView] shouldNot] beNil];
[[[[sut alertView] title] shouldNot] beNil];
[[[[sut alertView] message] shouldNot] beNil];

我在5.1上也遇到了同样的问题,我也看到了这一点,这正是我昨晚在我的项目中发现的。所涉及的方法包含一个
UIAlertView
。很好。我已经验证了,我仍然在Xcode 5.0.2上工作,并且在Travis CI上运行测试时,它不会导致问题。我已经向AppleNice提交了一个bug!我在如果你在你的项目中使用mock:)你把我引向了正确的方向!使用Ocmocito无法处理我所知道的高级模拟查看Jon Reid的。