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

通知测试用例

    -(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 

我正在尝试涵盖上述通知方法的测试用例,但它给了我错误,说无法识别的选择器已发送到实例!

任何人都建议我涵盖通知方法的测试用例

@提前致谢

4

1 回答 1

0

除了我认为setUptearDown(注意大写)的意外拼写错误之外,这段代码没有任何问题。我放了一个断点onDidFinishLaunchingNotification:,它被测试触发了。

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

于 2013-03-19T03:31:29.720 回答