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");
}

Test Case for Notification

    -(void)setup{
        [super setUp];

    mClassObj = [[ClassA alloc]init];

    }

-(void)teaddown{

mClassObj = nil;
    [super tearDown];


}
 -(void)testUIApplicationDidFinishLaunchingNotification {

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

Expecting this will work!

But Test Case failed

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

I am trying to cover the Test case for the above notifications method but its giving me error saying unrecognized selector sent to instance!

Any one advice me to cover the test case for the notification methods

@Thanks In advance

Kiran
  • 345
  • 1
  • 4
  • 16

1 Answers1

0

Other than what I assume are accidental typos for setUp and tearDown (watch the capitalization), there's nothing wrong with this code. I put a breakpoint on onDidFinishLaunchingNotification: and it gets triggered by the test.

The question is, how is a constant NSString sneaking in there?

Jon Reid
  • 20,545
  • 2
  • 64
  • 95