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在提前