- (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];
}
Очаквам, че това ще проработи!
Но Test Case се провали
-[__NSCFString onDidFinishLaunchingNotification:]: unrecognized selector sent to instance
Опитвам се да покрия тестовия случай за горния метод за уведомяване, но ми дава грешка, казвайки, че неразпознат селектор е изпратен до инстанцията!
Някой да ме посъветва да покрия тестовия случай за методите за уведомяване
@Благодаря предварително