Issue with Unit Tests in Xcode 5.1 / iOS 7.1: assertion failure in BKSEventFocusManager

StackOverflow https://stackoverflow.com/questions/22335403

  •  13-06-2023
  •  | 
  •  

문제

Seeing the following error when running XCTest-based Logic Tests after upgrading to Xcode 5.1 - would love to know of a workaround.

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
도움이 되었습니까?

해결책

I have found that the minimal case to reproduce this is the following

#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

It seems like showing an UIAlertView in a test cause this problem. This was working in Xcode 5.0, but is broken in Xcode 5.1.

  • Xcode Version 5.1 (5B130a)
  • OSX Version 10.9.2

If you are having this problem try the above code and see if it's reproducable

다른 팁

I'm using Kiwi BDD to run my test cases (called Specs in Kiwi). I've been able to silence this assertion failure by mocking a UIAlertView, stubbing the -show method and using the mock finish the test method.

Here's an example of my code:

[[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)

Edit: I also avoided the assertion failure by making the UIAlertView a property of the UIViewController.

[sut methodYouWantToTest];
[[[sut alertView] shouldNot] beNil];
[[[[sut alertView] title] shouldNot] beNil];
[[[[sut alertView] message] shouldNot] beNil];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top