【问题标题】:Issue OCUnit Test Case for Notification发布通知的 OCUnit 测试用例
【发布时间】:2013-03-04 13:25:48
【问题描述】:
- (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 

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

有人建议我覆盖通知方法的测试用例

@提前致谢

【问题讨论】:

    标签: iphone ipad ocunit


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 2019-06-23
      相关资源
      最近更新 更多