- (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
我试图覆盖上述通知方法的测试用例 但它给我的错误说无法识别的选择器发送到实例!
任何人都建议我介绍通知方法的测试用例
@Thanks提前
答案 0 :(得分:0)
除了我假设的setUp
和tearDown
(观察大写字母)的意外拼写错误之外,此代码没有任何问题。我在onDidFinishLaunchingNotification:
上放了一个断点,它会被测试触发。
问题是,一个不变的NSString如何潜入那里?