- (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");
}
通知のテスト ケース
-(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
上記の通知メソッドのテスト ケースをカバーしようとしていますが、認識されないセレクターがインスタンスに送信されたというエラーが表示されます。
通知方法のテストケースをカバーするようにアドバイスしてください
@前もって感謝します