- (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
我正在尝试涵盖上述通知方法的测试用例,但它给了我错误,说无法识别的选择器已发送到实例!
任何人都建议我涵盖通知方法的测试用例
@提前致谢