2013-03-04 54 views
0
- (id)init 
{ 
    if (self = [super init]) 
    { 

     [[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(onDidFinishLaunchingNotification:) 
                name:UIApplicationDidFinishLaunchingNotification 
                object:nil]; 
     [[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(onWillEnterForegroundNotification:) 
                name:UIApplicationWillEnterForegroundNotification 
                object:nil]; 
     [[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(onDidBecomeActiveNotification:) 
                name:UIApplicationDidBecomeActiveNotification 
                object:nil]; 
     [[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(onWillTerminateNotification:) 
                name:UIApplicationWillTerminateNotification 
                object:nil]; 
    } 

    return self; 
} 

// Notification Observers 
- (void)onDidFinishLaunchingNotification:(NSNotification*)notification 
{ 
    NSLog(@"onDidFinishLaunchingNotification"); 

} 

- (void)onWillEnterForegroundNotification:(NSNotification*)notification 
{ 
    NSLog(@"onWillEnterForegroundNotification"); 

} 
- (void)onDidBecomeActiveNotification:(NSNotification*)notification 
{ 
    NSLog(@"::onDidBecomeActiveNotification"); 
} 

- (void)onWillTerminateNotification:(NSNotification*)notification 
{ 
    NSLog(@"onWillTerminateNotification"); 
} 

测试用例通知问题的OCUnit测试案例的通知

-(void)setup{ 
     [super setUp]; 

    mClassObj = [[ClassA alloc]init]; 

    } 

-(void)teaddown{ 

mClassObj = nil; 
    [super tearDown]; 


} 
-(void)testUIApplicationDidFinishLaunchingNotification { 

     [[NSNotificationCenter defaultCenter]postNotificationName:UIApplicationDidFinishLaunchingNotification object:nil];  
     } 

期待这将工作!

但测试用例失败

-[__NSCFString onDidFinishLaunchingNotification:]: unrecognized selector sent to instance 

我试图以支付上述通知的方法 测试案例,但其给我的错误说无法识别的选择发送到实例!

的任何一个建议我去覆盖测试用例的通知方法

@Thanks在提前

回答

0

比我假设是setUptearDown意外的排字错误(观看大小写)其他,没有什么错与此代码。我在onDidFinishLaunchingNotification:上设置了一个断点,并由测试触发。

现在的问题是,一个常量NSString是如何潜入其中的?